Jeremy Stover

Member
  • Content count

    6
  • Joined

  • Last visited

Community Reputation

104 Neutral

About Jeremy Stover

  • Rank
    Newbie
  1. Minimax for Tic Tac Toe

    :edit, accidentaly posted twice. Sorry
  2. Minimax for Tic Tac Toe

    [quote name='Jaap85' timestamp='1340828179' post='4953441'] i dont see the error in your code here yet. What happens to the value of nValidMoves.Count in the endless loop? Does it decrease and increase? Or does it stay the same? Also, what does the SetSquare function do exactly. Do you have the code for that? [/quote] The set Square function only sets the square in the copy of the current game board. And to be honest, it seems like nValid moves is working fine. Towards the start of the game, the count is 6, and after I let it run for a little while, the count is at 2, never at zero as far as I can see though. I do know that I never reach past the' int nscore = Min(allNodes[0,0]);' BTW, setSquare is now setNewMove, It takes the board that we are testing, the position to place a chip, and either player, or an empty space to play there. You see at the bottom of the Min() and Max() function, I get rid of all the new spaces tested. I think at least. That what I intended. the code for setNewMove() is... [source lang="csharp"] /// <summary> /// Sets the new move into the boardArray /// </summary> /// <param name="newMove"> vector2 position in the board array to set the new move</param> public void setNewMove(Vector2 newMove, int player) { boardArray[(int)newMove.X,(int) newMove.Y] = player; }[/source] and that is part of my board class, which just holds the actual version of the board, and the one that is being cycled through. :Thanks for your help btw, I really appreciate it.:
  3. Minimax for Tic Tac Toe

    Ok, I have been looking through this relentlessly, Still throwing me into an infinite loop. Could you guys look through my new code when you have a chance and see what my problem is. Thanks a bunch for all your help. [source lang="csharp"] public Vector2 updateMINIMAX() { int bestscore = -1000; List<Vector2> bestMoves = new List<Vector2>(); List<Vector2> nValidMoves; nValidMoves = allNodes[0, 0].validMoves(); while (nValidMoves.Count != 0) { allNodes[0, 0].setNewMove(nValidMoves.First<Vector2>(), 2); int nscore = Min(allNodes[0,0]); if (nscore > bestscore) { bestscore = nscore; bestMoves.Clear(); bestMoves.Add(nValidMoves.First<Vector2>()); } else if (nscore == bestscore) { bestMoves.Add(nValidMoves.First<Vector2>()); } allNodes[0, 0].setNewMove(nValidMoves.First<Vector2>(), 0); nValidMoves.Remove(nValidMoves.First<Vector2>()); } return bestMoves.First<Vector2>(); } private int Min(Board tempBoard) { int moveScore = tempBoard.winCheck(); if (moveScore != 0) return moveScore; int nBestScore = 1000; List<Vector2> nValidMoves; nValidMoves = tempBoard.validMoves(); while (nValidMoves.Count != 0) { tempBoard.setNewMove(nValidMoves.First<Vector2>(), 1); int nScore = Max(tempBoard); if (nScore < nBestScore) { nBestScore = nScore; } allNodes[0, 0].setNewMove(nValidMoves.First<Vector2>(), 0); nValidMoves.Remove(nValidMoves.First<Vector2>()); } return nBestScore; } private int Max(Board tempBoard) { int moveScore = tempBoard.winCheck(); if (moveScore != 0) return moveScore; int nBestScore = -1000; List<Vector2> nValidMoves; nValidMoves = tempBoard.validMoves(); while (nValidMoves.Count != 0) { tempBoard.setNewMove(nValidMoves.First<Vector2>(), 2); int nScore = Min(tempBoard); if (nScore > nBestScore) { nBestScore = nScore; } allNodes[0, 0].setNewMove(nValidMoves.First<Vector2>(), 0); nValidMoves.Remove(nValidMoves.First<Vector2>()); } return nBestScore; } [/source]
  4. Minimax for Tic Tac Toe

    I was lookign through my code, and I founf my problem. It wasn't returning the game over right, and it was throwing me into an infinite loop lol. Sorry for being an ahole
  5. Sorry, I put this up and then saw it, very relevant info lol So I will attempt to delete this if I can, if not, have at it mods
  6. Hey everyone, I am developing a connect four clone, I have just about all the features developed that I want, but the AI is to easy. As of right now, I have a list of "Attack" moves that will make the Computer Win, and a list of "Defend" moves that will block the players wins. If it cannot see either of those possible moves, it places randomly. The game plays, but it is far to easy to trick the computer. I find it to be far to close to equivalent of a novice player. I see the problem that it cannot look into the future. It can only 'see' what is currently being played. So I decided to implement the MINIMAX tree, with a simple pruning algorithm. As I have no experience in this area, and only have a general idea of MINIMAX, could I get some help? I under stand the basic premise of the algorithm, yet I cannot seem to get an idea of how to implement this. I have an array holding the play field data, 0 being empty, 1 being the player, and 2 being the computer. Player one goes first. And the loser goes first the next game. Regardless, I have no idea on how to start implementing this. Would I hold an array of the play field for each possible move? Or would I have an array for a set of moves and score that array? I guess the latter would save a lot of memory, Then, would I use a for loop on each set of moves to create an array for a different move? Then check to see if that move is a win or lose, and if not, do it again? I guess what I am looking for is a very simple pseudo code version of what I have to do. Thanks for your help guys.