Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
I've to choose an algorithm for a given problem:
The game has two players: x and o. The players take alternate turns, with player x moving first at the beginning of each game.
Player x starts at position (1,1) while o starts at (8,8).
Each turn, a player can move like a queen in chess (in any of the eight directions) as long as her path does not cross a square already filled in or occupied. After moving, the space vacated by the player is designated as filled and cannot be moved to again. Notice that only the space that was occupied is filled, not the entire path.
The game ends when one player can no longer move, leaving the other player as the winner. Time given is 1 minute.
The coordinate (1 1) indicates the top left hand side of the board.
The board is specified as a list of rows. Each row is a list of entries:
is an empty square
is a filled in square
x is the current position of the x player
o is the current position of the o player
Would that be a local search algorithm or A*? It seems similar to chess, but at the same time I can't really see a goal of this game...
Loads of thanks!
This is a zero sum game, with two players, and each agent have full 'knowledge' of the world.
The general approach to handle such problems is minimax algorithm.
The algorithm idea in a nutshell is trying to find the maximal guaranteed "value" for each move. This is done by taking the "max" possibility in your turn and "min" possibility in the opponent's turn (it is assuming he is also trying to maximize his profit, so maximizing his profit is minimizing your profit).
The algorithm looks recursively into all possible game states up to certain depth, and choose the best strategy you can take.
You will likely need some heuristic function to evaluate each game state (since the algorithm is unlikely to be able to have the entire game tree, due to the large branch factor). The algorithm will use this heuristic to chose the best move for you, and for the oponent.
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I am creating a program to solve this puzzle in the lowest cost
The sliding-title puzzle consists of three black titles, three white titles, and an empty space in the configuration shown in the Figure.
WWW_BBB
The goal of the puzzle is to get all white tiles to the right of the
black tiles while the location of the space does not matter
The puzzle has two legal moves(i.e. actions) with associated costs:
• A title may move into an adjacent empty location. – This has a step cost of
• A title can hop over one or two other tiles into the empty position.
– This has a step cost equal to the number of tiles jumped over.
I am having troubles understand how to create a Heuristic algorithm to be implemented in the algorithm.
I understand the implementation of Dijkstra's algorithm within this problem, but can't figure out how to then make it into the A* algorithm.
Assuming you want to use A* on the graph of puzzle states with edges to the states reachable through one of the two rules, then a good heuristic to use would be the number of inversions: https://en.wikipedia.org/wiki/Inversion_(discrete_mathematics)
That's the number of W,B pairs that are out of order (assuming that the relative order of same-colored tiles doesn't change). The W's and B's are in order when the number of versions is 0, and the number of inversions fixed by each type of move is less than or equal to its cost. Therefore the number of inversions as a heuristic will never overestimate the cost of the best sequence.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 8 years ago.
Improve this question
Suppose a ant is placed on the position (0,0) of a chess-board. That ant wants to walk through every single tile of the board, while walking the least it can to do so. What path it must follow? Is there a formula F(i) that returns the position of the ith tile on that path?
Edit: as requested, I've tried the following:
I tried googling for keywords such as "shortest path", "shortest path in square grid", but couldn't find anything relevant.
I then downloaded, configured and used a Traveling Salesman Problem solver in a square grid. Obviously, the solution wasn't satisfactory, but I could gain an insight on the problem. There is an illustration of my results:
I then, intuitively, speculated wether the answer could be something like the Hilbert Curve: . I googled about it and asked on a IRC programming channel, but I couldn't find any actual evidence this is better than spirals and similars, nor a proof this is the best possible solution.
EDIT 2: Further clarifications:
The ant can move diagonally. The distance refers to the euclidean length of the line defined by the path.
Walk in straight line, with the edge of the board on your left, until you either hit the edge of the chess board or a tile you have visited before. If you do, then take a right.
Or a thousand other obvious patterns.
Any path that takes 63 steps is the minimum and just as good as any other path.
This is going to depend on if you're taking the width of each square into consideration or is this just a double array question?
If we're talking a double-array question f(x,y), then the answer is that there is no least path because the ant will need to travel to each square f(x,y) = x*y, so f(8,8) = 64.
If we start taking the width of the tiles themselves into consideration, then the answer is somewhat different because we can use some strategies to get the least amount of distance traveled (such as starting in the center, staying by the grid separators and walking in a roughly spiral pattern r=xy^(theta)).
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I have two polygons as shown in the image below.
The left one is "rough polygon" and the right one is "final polygon"
Now, I'm looking for algorithm to fit "final polygon" inside "rough polygon" with best maximum scale.
you can rotate as well as translate "final polygon" as much as you want.
you can't perform individual x dimension or y dimension scaling.
you can only perform uniform scaling (where value of Sx and Sy are same).
Here is a possible line of attack for an exact solution by exhaustive trials; just ideas.
My guess is that a solution is achieved when there are three contacts. I mean three vertexes of either polygon touching an edge of the other or conversely. (If there are less than three contacts, you can inflate the internal polygon so that it comes into a third contact.)
Given two arbitrary triangles, it shouldn't be so difficult to find all possible three-contact positions.
So the global scheme is to take all triples of vertexes/sides from one polygon, and take all complementary triples of sides/vertexes of the other. For every combination, momentarily consider that you have triangles and find the possible three-contact positions. For for every candidate position check if the inner polygon stays confined in the outer one. In the end, keep the admissible solution with the largest scale factor.
For polygons with N and M sides, there will be O(N³M³) configurations to try, and the containment test can be as costly as O(NM). So this approach is only viable for very small polygons.
Scale the rightside polygon by 0.01. (geometrical)
Start spinnning it so fast that it draws circle. (geometrical)
Start incrementing the scale 0.01 by 0.01. (geometrical)
Stop when it touches the outer polygon. (geometrical)
Then bounce it to opposite direction until it bounces again. (physical)
Again and again.(iterations)
Until it cannot move/bounce again.(stuck optimally) (physical)
Use simulated annealing in case of false local solutions.(you need global solution)
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
I have to either give a tiling of the figure below by dominoes, or give a proof that it is impossible.
I think to achieve this I have to find a perfect matching of the asociated graph of the figure (every space is a node of the graph and they are connected by edges in the vertical and horizontal way). So the graph is undirected and not bipartite. The number of nodes is 42, so could be possible due to there are an even number of nodes, but I think it's not possible. I thought about the definition that a graph has a perfect matching iff |V|=2·v(G) (where v(G) is the matching number of the graph).
Could you help me to find the tiling if it's exists or continue the proof that it's not possible?
According to Hall's matching theorem, if you choose any subset from one "part" of bipartite graph and the number of vertices adjacent to vertices of this subset is smaller than the subset size, there is no perfect matching.
If we choose 11 green tiles as shown below, we get only 10 adjacent tiles for them. Which means there is no perfect matching and you cannot cover the figure by dominoes.
That is impossible.
Each domino tile consists of one even and one odd square.
Blue area contains equal quantity of odd and even squares.
Yellow squares are even, green are odd.
Consider set of domino tiles that have at least one square inside Blue+Yellow area.
They may also cover some squares in green area.
But in any case it is impossible to equate number of even and odd squares for this set of domino tiles.
I chose to attack this problem using proof by cases. I haven't reached the end of each case, but the work so far suggests that every possibility leads to a dead end, so I think the tiling should be impossible. Have fun filling out the rest of the proof. =)
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
Refer this link: http://en.wikipedia.org/wiki/Hex_(board_game)
I'm making Hex game, but I have no idea to check given game is ended.
So What the great algorithm check that given game is ended?
In here, ending means that exactly one person connect completely a line.
Question: Given positions of pieces of two players, What's the good algorithm to determine "Is there a complete line that makes game end?"
You need an equivalence class data structure, sometimes known as a "union-find" structure: http://en.wikipedia.org/wiki/Disjoint-set_data_structure
As each stone is placed, it is given a new equivalence class. Then, the equivalence classes of that stone and all its neighbours of the same colour are merged. Have "virtual stones" of each colour along each edge of the board. When opposing edge stones of the same colour are in the same equivalence class, then a connection is made and the game is over.
Hope this helps.
Each piece has a side it's connected to (or no side), and is a part of a little cycle of pieces that are all connected. When a piece is placed, it checks if any adjacent piece is connected to a side, then links all adjacent cycles of pieces and adjusts their "side", if necessary. If it sees two sides, the game is over.
This is very similar to the algorithm used in go to determine if a group is captured.
I Think A* is the right algorithm for you,
though it will be too straight forward, the computer will be playing very boring.
you can take a look at A* Tutorial
or play with an implementation