söndag 26 december 2010

TRON B - A simplified game of Tron using MINIMAX

I have coded a Tron game clone to further see what the MINIMAX strategy can do. For those who are not familiar with the rules and game mechanics of Tron will here follow a short explanation. Tron is a two-player game where each player controls a square inside a grid. When a player moves her square in a direction (up, down, left or right) the square will move to that location and leave a solid "wall" behind. Do not crash into "walls" or your opponent. If you do, you have lost the game.
The goal is to outlive your opponent.
For the AI of the computer I've implemented a MINIMAX strategy. This time around I'm not going trough the whole game tree (to time consuming for large grids), instead I've limited the search depth. The challenge here is to write a good utility function that evaluate the current game-state "correct". So far i have equipped my utility function to consider the amount of free space and a "trapability" factor when evaluating game-states. It is not the killer I want it to be yet but with a few more "tools" added to the utility function...

The start screen.



A game in action.
Game over!


fredag 3 december 2010

Tic-Tac-Toe using the MINIMAX strategy

I made a Tic-Tac-Toe game to see the minimax strategy in action and it works quite well, the AI still hasn't lost a game yet. There are fewer than 9! (362 880) games states in Tic-Tac-Toe so I can search trough the whole game tree for the optimal move. The utility function check for either a win, a loss, a draw or if the outcome of the game can't be decided yet and return a value accordingly.
I rank win > uncertain > draw > loss.

Tic-Tac-Toe

tisdag 16 november 2010

The MINIMAX strategy

I have been busy reading up on the MINIMAX strategy lately so I will try to share what I have learned so far. The MINIMAX strategy can be used to find the optimal decision/move in two-player or multiplayer zero-sum games. A zero-sum game is a game there one players gain equals the other players loss. Chess for example is a zero-sum game, either you win, lose or draw, but you can't both win and lose or draw at the same time. Consider the game tree for a trivial two-player game, each player take turns marking the space in a 2x2 grid, each space in the grid represent a specific point and the player who end up with most points wins the game. Let us decide the points for each of the spaces.

Upper-left corner = 1 Upper-right corner = 2 Lower-left corner = 3 Lower-right corner = 4

So, how do we find the optimal move? Basically what we need to do is to traverse trough the whole game tree until we reach the leaves (a leaf is a node without any children), once there we use a so called utility function to calculate a numerical value for the leaf. With the utility values we can now determine the minimax values for nodes higher and higher up in the game tree as we unwinds back up to the initial state. A utility function evaluate the game state to determine how strong the position is for the player. So one player wants to maximize the utility function and the other player wants to do the opposite (minimize). In our example MAX's (A) best move in the initial state is to take the lower-right corner, because it leads to the state with highest minimax value. But let us assume that MAX is malfunctioning and choose to take the upper-left corner instead. What is MIN's (B) best reply? Remember that MIN wants to move to a state with the lowest minimax value and what is MAX's best reply after MIN's turn provided not malfunctioning anymore :).

A (partial) game tree for a trivial game, where the nodes are game states and the edges (lines) are moves.




tisdag 19 oktober 2010

GraphPlotter

I was browsing trough a textbook when this picture depicting a graph caught my attention. I thought HEY!, maybe I can write a program in Java that can draw such things on my monitor. So here is my quick attempt "the GraphPlotter". Bare in mind that my programming skills is at best poor, but I'm willing, and it is my intent to improve it.

GraphPlotter reads a textfile (in a convenient input format) and then plot the corresponding graph on the screen.The small dots represents the direction of the lines.

A graph with 5 nodes.
    
Things get a little messy with 50 nodes.

As you can see there is lots of room for improvements so suggestions and comments are always welcome but for the time now being I'm happy with it as it is.

Alive!

Welcome to Chain of Causality!