How many plies deep can I realistically search using minimax in connect 4?
Is it possible to search through the entire game starting at turn 1?
If not, on what turn is it feasible to search the board fully?
Based on personal experience I can tell you that from the starting position, if you really fine tune your algorithm, with a coarse evaluation, and a good transposition table, you can get around 11 ply deep. If you want to include techniques that are not theoretically sound (but are good in practice), such as Late Move Reductions and Futility Pruning, 15 ply might be feasible.
When a column of the board fills up, the branching factor decreases from 7 to 6. This greatly increases how deep you can go. Depending on how full the board is, it would take between two to three columns full before you could search to the end of the game.
Related
I have been trying to find a algorithm to strongly solve the game Teeko. The game is played on a 5x5 board were each player has 4 pieces and attempts align them in any direction or create a square out of them. (assume there is no drop phase)
I have tried solving the game by using a negamax with alpha beta pruning and other optimizations like a transposition table but that has not seemed to have worked because the solver would usually get stuck in loops were neither player wants to deviate from there strategy as it would result in them loosing. From my research I have found stuff like Nash Equilibrium as a potential solution but I cant figure out how to implement it. Furthermore, I have found that the game has been solved and found that the with prefect play it result in a draw previously: https://pcarrier.com/teeko/text/teeko.results.txt
Are there any algorithms that might be able to give the same result as minimax and hanlde repeating positions and how could I implement it and are there any other algorithms that give the same result as minimax?
Minimax (or Negamax) is well capable of handling repeating positions using transposition tables, as you mention in your question. Transposition tables are complicated to implement though so maybe you have a bug?
The problem with minimax is that you either:
NEed to solve it until the game is completed to get a score. This is possible for simple games like tic-tac-toe, but not for more complicated games like chess.
Score each node using some heuristic function, which is the case for e.g. chess.
I am not sure about Teeko, is it possible to get to all leaf nodes with minimax and alpha beta pruning? Could you do other things to reduce the search tree, like transpotision tables or other cut offs? If so then minimax is a great option.
Is it possible to create some kind of evaluation function for this game? It seems hard to me, but maybe that is because I know too little about the game. Is it better to have central squares? Better to get 2 in a row than to spread out pieces? Evaluation function is something you could have a look at if you are a good player of the game, or find good sources online.
I'm working with a 2D point cloud and I want to find the shape that it follows, and determine whether it is a closed loop or not. You'll have to excuse my terrible paint illustration, but essentially I want to be able to draw the red line from the black dots, and confirm whether it is closed or not. I'm currently looking through methods like RANSAC etc but they all seem suited to slightly different tasks than the one I face. I'll be implementing the solution in C++.
Does anyone know a good approach/algorithm to calculate the red line, given the black points, and determine whether it closed?
My recommendation would be to:
Triangulate the point set.
Find the short path through all lines, basically the traveling salesman problem. The greedy algorithm is probably good enough for this purpose.
Use a line simplification algorithm to "tidy up" the line (RDP algorithm works pretty well).
Consider anything greater than X times the average distance between points (from step 2), basically outliers in the data as gaps to determine if open or closed.
Keep in mind steps #3 and #4 are highly opinionated. They both require you to define what you consider is "good enough", and will require some experimentation to set the best values.
How graph algorithms can be used in line follower maze solving robot. I have solved grid using DFS search but do not know how to implement it actual line follower robot. my shortest path finding implements on a 20 by 20 grid . where s= start and g = destination and numbers denotes the position of each point inside the grid (row by row basis).
-If you are a beginner to microcontroller, then i would recommend you to first achieve in making your robot follow the line .
-If robot performs well in line following then you should try it in making your robot pass the strips(junctions in the grid) and make your robot transverse complete grid(all co-ordinates of the grid), simultaneously you can make a count of number of strips the robot passed(you can use two dimensional array to store there co-ordinates).
-If you can achieve the above two tasks then you are good to go for applying your logic in solving the maze inside the grid.
I once implemented shortest path algorithm on AVR board.
Here are the steps that you should follow.
Step 1: Do a dry run of arena and save all coordinate in an 2-D array. As you have described, there seems to be two type of junction. Make sure to blink a different LED on board every time you pass a junction. This way you can make sure that you are reading the board correctly.
Step 2: Now you have all the coordinates in a 2D array. You are applying DFS. I would not recommend that. since you have a grid not a tree to solve. Use Dijkstra's algorithm.
Implementation of this should not be hard. As compiler of AVR is very much similar to C.
Step 3: Now follow the result. lets day you have a 8*8 array. define a numbering from 1 to 64. your output should be in form of
1 9 10 18.... so on
Now calculate difference between two adjacent number
8, 1, 8 and so on
and fix a move for every number like for 8 go on left , for 1 go north. Just keep your current direction in mind to make move to other direction. Like going north from west would be different from going north from east.
Again I would recommend you to display your final result on LED first. Sometime your algorithm works fine and hardware stops working.
Shortest path algorithm for line follower robot, which do not involve loops in the line are relatively easy to implement.
It can be made by exhaustively traversing through all possible routs, making a default left/right turn at every decision making point. This way if there are no loops in the track, the robot will eventually get to the destination. The robot should keep track of all the turns that were made until the destination is reached.
After that it is a matter of reduction to eliminate the unnecessary turn the robot had made. I have discussed this shorted path algorithm in detail at my blog here.
I'm currently writing a program that will simulate in very basic terms the diffusion and pressure of a gas in a 3D volume with boundaries throughout - Think for example an ant cave.
The effects I want to achieve:
1. Gas diffuses throughout the environment over time, respecting walls.
2. I'd like to measure pressure, or the compression of the gas, per grid point. The effect of this should be that if a room is opened the gas will diffuse out of the opening in a speed that reflects the pressure difference.
My problem is that I lack the knowledge to fully understand theoretical math equations, and to be honest I'm really not looking for an accurate simulation. I'd just want to achieve some of the prominent effects of the physics at play. I'm not interested in fluid dynamics (For example the simulation of smoke).
I'll be writing this program in OpenCL but happy to take any form of code examples, be it C or pseudo code.
I'm thinking I should pass in 3 3D arrays - One for the gas, one that defines the walls (eg 1 at xyz = wall), and one to store the pressure.
I'm currently assuming checking for the wall is easy enough. One simply checks each neighbour cell for it and account for the cell if its not a wall:
For each grid point,
is wallmatrix[x+1] a wall?
[diffusion math here]
is wallmatrix[x-1] a wall?
[diffusion math here]
is wallmatrix[y+1] a wall?
[diffusion math here]
etc...
But I'm just not sure what to do with the diffusion math, nor how I would include pressure in all this?
Diffusion is one of the easiest things to simulate because it's self smoothing.
For example, you could run your simulation in terms of constant time steps and keeping track of the individual particle positions, and at each time step move each particle a fixed (small) distance, but in a random direction.
There are other ways too, for example, you can do a grid based approach, where change the number of particles in each grid location.
A slight issue with your question is where you say, "diffuse out of the opening in a speed that reflects the pressure difference". Diffusion doesn't really do this, since diffusion is just the random motion of particles. I think, though, that even straight diffusion might look satisfying to you here, since the gas will diffuse out of an opening, and it will look faster. Really what will be happening though is that it will be diffusing out at the same speed as everywhere else, it's just that nothing will be diffusing back in. Still, if this isn't satisfying, then you will need to get into fluid dynamics, at least a bit, since this is how one describes how fluid behaves when there's a pressure gradient, not diffusion.
Well, this is not an easy task!
First of all: you want to simulate basic diffusion OR the complete motion of the gas? The second case isn't easy at all, but you can get an idea here.
If you just want to diffuse a gas in an static environment, things are easier but you can't measure the
total pressure, your only variable will be the local concentration of the gas.
This phenomena is governed by the Fick laws; the second one is probably what you are looking for.
Read for finite difference methods to understand how to discretize the diffusion equation.
The subject is quite big to write a complete answer here.
I want to find path in 2d platform game, teeworlds. The player there can move left/right, jump, and use hook, that lets you move upward the wall or move under ceiling. Well, its hard becouse normal pathfinds like a* or bfs cant exist here, cuz you cant just move up. I need to find path btw 2 players so 1 can go to the second one. There are 3 types of tiles, collide, nohook (you cant hook it) and nothing (air). I have the map in format int map[w][h] where 0=air, 1=collide, 2=nohook. map isnt modified for whole game time.
I have completly no idea how to do that. If you can help me, I'd be pleased.
PS. The question is general about platform games, teeworlds is only one of them...
From the pathfinding algorithm's standpoint you could treat the climbable walls as if they were normal walkways, so the algorithm does not stop there.
I don't think I completely understand the possibilities in your game. But this is how it works in general:
Path finding algorithms work on graphs (directed, undirected, with costs or equal costs for all edges doesn't matter). All you have to do is model your graph according to your game's rules. I.e. if there is only a normal way between field i and j than cost(i,j) = normal, if there is an additional way to use a hook, it could would be that cost(i,j) = min(hook, normal) . and so on. Once you have a graph (i assume it has to be directed for your game) all the normal Pathfinding algorithms will work.
if there are requirements like "you can only use hook n-times", a multi-label dijsktra can work.
pathfinding algorithms work on graphs in general
movement from one cell to another means that there is a connection between two cells (for instance in four directions). But you can also link to some other cell (the ceiling).
A* as a general search algorithm can still be applicable here, you just need to find a way to represent your platform game path-finding problem as a general search problem. So while you might have been introduced to A* as an algorithm to find a path through a grid-like maze, that is just a specific case of such a general search problem.
The more general case being graphs, where edges represent moves or actions and nodes represent positions or states.
One way to use A* for the game you mention is by taking an example from this Infinite Mario AI. This implementation of A* works locally and is rerun every tick to get the most optimal actions at that exact moment which is great for a fast-paced game like Mario or the game you mention, but be mindful that this is different from A* when it's used to solve a maze, in which case the path is found only once and it is like a global plan to be followed until its end.
Use simple BFS method, preprocessing the pairs to nodes.