public override bool terminalTest(GameState state) { TicTacToeBoard board = (TicTacToeBoard)state.get("board"); bool line = board.lineThroughBoard(); bool filled = board.getNumberOfMarkedPositions() == 9; return(line || filled); }
public Object clone() { TicTacToeBoard newBoard = new TicTacToeBoard(); for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { String s = getValue(i, j); newBoard.setValue(i, j, s); } } return(newBoard); }
private int computeUtility(TicTacToeBoard aBoard, string playerToMove) { int retVal = 0; if (aBoard.lineThroughBoard()) { if (playerToMove.Equals("X")) { retVal = -1; } else { retVal = 1; } } return(retVal); }
public GameState getMove(GameState state, int x, int y) { GameState retVal = null; XYLocation loc = new XYLocation(x, y); ArrayList moves = getMoves(state); ArrayList newMoves = (ArrayList)moves.Clone(); if (moves.Contains(loc)) { //int index = newMoves.indexOf(loc); int index = newMoves.IndexOf(loc); //newMoves.Remove(index); //.remove function is not overloaded in .net like it is in java //in .NET .remove only removes the instance of the parameter, //not the object at the index newMoves.RemoveAt(index); retVal = new GameState(); retVal.put("moves", newMoves); TicTacToeBoard newBoard = getBoard(state).cloneBoard(); if (getPlayerToMove(state) == "X") { newBoard.markX(x, y); retVal.put("player", "O"); } else { newBoard.markO(x, y); retVal.put("player", "X"); } retVal.put("board", newBoard); retVal.put("utility", computeUtility(newBoard, getPlayerToMove(getState()))); retVal.put("level", getLevel(state) + 1); //presentState = retVal; } return(retVal); }
public override bool Equals(Object anObj) { bool retVal = true; TicTacToeBoard anotherBoard = (TicTacToeBoard)anObj; bool secondBreak = false; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { if (anotherBoard.getValue(i, j) != getValue(i, j)) { retVal = false; secondBreak = true; break; } } if (secondBreak == false) { break; } } return(retVal); }
private int computeUtility(TicTacToeBoard aBoard, string playerToMove) { int retVal = 0; if (aBoard.lineThroughBoard()) { if (playerToMove.Equals("X")) { retVal = -1; } else { retVal = 1; } } return retVal; }
public Object clone() { TicTacToeBoard newBoard = new TicTacToeBoard(); for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { String s = getValue(i, j); newBoard.setValue(i, j, s); } } return newBoard; }