private AbstractMove getRandomFirstGoatMove(State s) { Random r = new Random(); int randInt = r.Next(4); BoardSpace b = null; switch (randInt) { case 0: b = new BoardSpace(0, 2); break; case 1: b = new BoardSpace(2, 0); break; case 2: b = new BoardSpace(2, 4); break; case 3: b = new BoardSpace(4, 2); break; } GoatPlacementMove m = new GoatPlacementMove(null, b, s.Goat); return m; }
public override void ExecuteMove(State state) { state.Board.SetState(StartSpace.GetRow(), StartSpace.GetColumn(), 'X'); state.Board.SetState(EndSpace.GetRow(), EndSpace.GetColumn(), player.Symbol); }
public void TestSlideMovesMove() { State s = new State(); Board b = s.Board; Assert.IsNotNull(b.GetSpace(1, 3)); Assert.IsNotNull(s.Tiger); AbstractMove g = new GoatPlacementMove(null, b.GetSpace(1, 3), s.Goat); g.ExecuteMove(s); AbstractMove ts = new SlideMove(b.GetSpace(4, 4), b.GetSpace(3, 3), s.Tiger); Assert.IsNotNull(ts.StartSpace); Assert.IsNotNull(ts.EndSpace); Assert.IsNotNull(ts.Player); ts.ExecuteMove(s); Assert.AreEqual(b.GetSpace(4, 4).GetSpaceState(), 'X'); Assert.AreEqual(b.GetSpace(3, 3).GetSpaceState(), 'T'); AbstractMove gs = new SlideMove(b.GetSpace(1, 3), b.GetSpace(1, 4), s.Goat); gs.ExecuteMove(s); Assert.AreEqual(b.GetSpace(1, 3).GetSpaceState(), 'X'); Assert.AreEqual(b.GetSpace(1, 4).GetSpaceState(), 'G'); Console.WriteLine("Tested placement 1,3, tiger slide 4,4 to 3,3 and goat slide 1,3 to 1,4 \r\n" + s.Board.GetBoardPic()); }
public void TestIsTigerGoalState() { State s = new State(); Board b = s.Board; Assert.IsNotNull(b); Assert.IsNotNull(b.GetSpace(2,2)); Assert.IsNotNull(s.GetSpaceState(2,2)); GoatPlacementMove g = new GoatPlacementMove(null, b.GetSpace(1, 3), s.Goat); TigerCaptureMove t1 = new TigerCaptureMove(b.GetSpace(0, 4), b.GetSpace(2, 2), b.GetSpace(1, 3), s.Tiger); TigerCaptureMove t2 = new TigerCaptureMove(b.GetSpace(2,2), b.GetSpace(0,4), b.GetSpace(1, 3), s.Tiger); Assert.IsFalse(s.IsTigerGoalState()); Assert.IsFalse(s.IsGoatGoalState()); g.ExecuteMove(s); t1.ExecuteMove(s); // 1 down g.ExecuteMove(s); t2.ExecuteMove(s); // 2 down g.ExecuteMove(s); t1.ExecuteMove(s); // 3 down g.ExecuteMove(s); t2.ExecuteMove(s); // 4 down g.ExecuteMove(s); t1.ExecuteMove(s); //5 down Assert.IsTrue(s.IsTigerGoalState()); Assert.IsFalse(s.IsGoatGoalState()); }
public override void ExecuteMove(State state) { Board b = state.Board; b.SetState(StartSpace.GetRow(), StartSpace.GetColumn(), 'X'); b.SetState(EndSpace.GetRow(), EndSpace.GetColumn(), Player.Symbol); b.SetState(JumpSpace.GetRow(), JumpSpace.GetColumn(), 'X'); state.Goat.IncrementGoatsKilled(); }
public override List<AbstractMove> GetCaptureMoves(State state, List<CoordinatePair> adjacentList, BoardSpace currSpace) { List<AbstractMove> captureMoves = new List<AbstractMove>(); int tempRow = 0; int tempCol = 0; int bRow = 0; int bColumn = 0; foreach (CoordinatePair b in adjacentList) { if (state.GetSpaceState(b.Row, b.Column) == 'G') { tempRow = currSpace.GetRow(); tempCol = currSpace.GetColumn(); bRow = b.Row; bColumn = b.Column; if (bRow == currSpace.GetRow()) { if (bColumn < currSpace.GetColumn()) tempCol = bColumn - 1; if (bColumn > currSpace.GetColumn()) tempCol = bColumn + 1; } if (bRow < currSpace.GetRow()) { tempRow = bRow - 1; if (bColumn < currSpace.GetColumn()) tempCol = bColumn - 1; if (bColumn > currSpace.GetColumn()) tempCol = bColumn + 1; } if (bRow > currSpace.GetRow()) { tempRow = bRow + 1; if (bColumn < currSpace.GetColumn()) tempCol = bColumn - 1; if (bColumn > currSpace.GetColumn()) tempCol = bColumn + 1; } if ((tempRow >= 0 && tempRow <= 4) && (tempCol >= 0 && tempCol <= 4)) if (state.GetSpaceState(tempRow, tempCol) == 'X') captureMoves.Add(new TigerCaptureMove(currSpace, state .Board.GetSpace(tempRow, tempCol), state .Board.GetSpace(bRow, bColumn), this)); } } return captureMoves; }
public void TestBoardCreated() { State s = new State(); Board b = s.Board; int row = 4; int col = 4; Assert.AreEqual(b.GetSpace(row, col).GetSpaceState(), 'T'); Assert.AreNotEqual(b.GetSpace(row, col).GetSpaceState(), 'Z'); Console.WriteLine("State test: printing Board Pic" + s.Board.GetBoardPic()); }
public AbstractMove ABSearchMax(State state) { List<AbstractMove> moves = state.findTigerMoves(); alpha = -1000; beta = 1000; int depthLimit = 4; //double v = maxNoPrune(state, depthLimit, moves); double v = maxValue(state, depthLimit, moves); return getMatchingMove(moves, v); }
public AbstractMove ABSearchMin(State state) { if (state.Goat.GoatsInHand == 20) return getRandomFirstGoatMove(state); alpha = -1000; beta = 1000; List<AbstractMove> moves = state.findGoatMoves(); int depthLimit = moves.Count > 9? 4: 5; double v = minValue(state, depthLimit, moves); //double v = minNoPrune(state, depthLimit, moves); return getMatchingMove(moves, v); }
public void TestCloneState() { State s1 = new State(); State s2 = s1.Clone(); Assert.AreNotEqual(s1, s2); int row = 3; int col = 3; Assert.AreEqual(s1.Board.GetSpace(row, col).GetSpaceState(), s2.Board.GetSpace(row, col).GetSpaceState()); Console.WriteLine("old state: \r\n" + s1.Board.GetBoardPic()); Console.WriteLine("new state: \r\n" + s2.Board.GetBoardPic()); }
public double GetEvaluation(State currState) { Board b = currState.Board; int status = 0; for (int rowCounter = 0; rowCounter < b.Spaces.GetLength(0); rowCounter++) for (int colCounter = 0; colCounter < b.Spaces.GetLength(1); colCounter++) if (b.GetSpace(rowCounter, colCounter).GetSpaceState() == 'G') status += 2; status += 2 * currState.Goat.GoatsInHand; return status; }
public override List<AbstractMove> FindMoves(State state) { List<AbstractMove> moves = new List<AbstractMove>(); if (goatsInHand > 0) moves = getPlacementMoves(state); else moves = getSlideandCaptureMoves(state, 'G'); return moves; }
public double GetEvaluation(State currState) { if (currState.IsTigerGoalState()) return 1000.0; if (currState.IsGoatGoalState()) return -1000.0; int killed = currState.Goat.GoatsKilled; double moveQuot = currState.Tiger.GetCountLegalMoves(currState) /30.0; return killed + moveQuot; }
public MoveJSON ChooseMove(String boardString, char p, int goatsKilled, int goatsInHand) { State s = new State(boardString); Tiger t = new Tiger(); Goat g = new Goat(); g.GoatsInHand = goatsInHand; g.GoatsKilled = goatsKilled; s.Goat = g; s.Tiger = t; MinMaxPlayer minMax = new MinMaxPlayer(t,g,s); //AbstractMove m = s.chooseMoveArbitrarilyForTest(p, goatsKilled,goatsInHand); AbstractMove m = (p=='T'?minMax.ABSearchMax(s):minMax.ABSearchMin(s)); return new MoveJSON(parseToString(m, s)); }
public void TestGoatPlacementMove() { State s = new State(); Board b = s.Board; Assert.IsNotNull(b.GetSpace(1, 3)); Assert.IsNotNull(s.Goat); AbstractMove g = new GoatPlacementMove(null, b.GetSpace(1, 3), s.Goat); Assert.IsNotNull(g.Player.Symbol); Assert.IsNotNull(g.EndSpace); g.ExecuteMove(s); Assert.AreEqual(b.GetSpace(1, 3).GetSpaceState(), 'G'); Assert.AreEqual(b.GetSpace(0, 4).GetSpaceState(), 'T'); Assert.AreEqual(s.Goat.GoatsInHand, 19); }
public void TestMoveList() { State s = new State(); Board b = s.Board; Assert.AreEqual(s.Goat.GetCountLegalMoves(s), 21); Assert.AreEqual(s.Tiger.GetCountLegalMoves(s), 12); GoatPlacementMove g = new GoatPlacementMove(null, b.GetSpace(1, 3), s.Goat); g.ExecuteMove(s); Assert.AreEqual(s.Goat.GetCountLegalMoves(s), 20); TigerCaptureMove t = new TigerCaptureMove(b.GetSpace(0, 4), b.GetSpace(2, 2), b.GetSpace(1, 3), s.Tiger); t.ExecuteMove(s); Assert.AreEqual(s.Goat.GetCountLegalMoves(s), 21); Assert.AreEqual(s.Tiger.GetCountLegalMoves(s), 17); }
protected List<AbstractMove> getSlideandCaptureMoves(State state, char ch) { List<AbstractMove> moves = new List<AbstractMove>(); List<CoordinatePair> adjacentSpaces = new List<CoordinatePair>(); BoardSpace currSpace = null; for (int rowCounter = 0; rowCounter < 5; rowCounter++) { for (int colCounter = 0; colCounter < 5; colCounter++) { currSpace = state.Board.GetSpace(rowCounter, colCounter); if ((state.GetSpaceState(rowCounter, colCounter)) == ch) { adjacentSpaces = state.Board.GetAdjacentList(rowCounter, colCounter); if (ch == 'T') { List<AbstractMove> captureMoves = GetCaptureMoves(state, adjacentSpaces, currSpace); foreach (AbstractMove m in captureMoves) moves.Add(m); } foreach (CoordinatePair c in adjacentSpaces) { char s = state.GetSpaceState(c.Row, c.Column); if (s == 'X') { moves.Add(new SlideMove(currSpace, state .Board.GetSpace(c.Row, c.Column), this)); } } } } } return moves; }
public void TestCloneMove() { State s = new State(); Board b = s.Board; Assert.IsNotNull(b.GetSpace(1, 3)); Assert.IsNotNull(s.Tiger); GoatPlacementMove g1 = new GoatPlacementMove(null, b.GetSpace(1, 3), s.Goat); GoatPlacementMove g2 = (GoatPlacementMove) g1.Clone(); Assert.AreNotEqual(g1, g2); Assert.AreEqual(g1.EndSpace, g2.EndSpace); TigerCaptureMove t1 = new TigerCaptureMove(b.GetSpace(0, 4), b.GetSpace(2, 2), b.GetSpace(1, 3), s.Tiger); Assert.IsNotNull(t1.StartSpace); TigerCaptureMove t2 = (TigerCaptureMove) t1.Clone(); Assert.AreNotEqual(t1, t2); Assert.AreEqual(t1.EndSpace, t2.EndSpace); SlideMove s1 = new SlideMove(b.GetSpace(4, 4), b.GetSpace(3, 3), s.Tiger); Assert.IsNotNull(s1.StartSpace); SlideMove s2 = (SlideMove) s1.Clone(); Assert.AreNotEqual(s1, s2); Assert.AreEqual(s1.EndSpace, s2.EndSpace); }
private double maxNoPrune(State state, int depthLimit, List<AbstractMove> moves) { if (state.IsGoatGoalState() || state.IsTigerGoalState() || depthLimit == 0) { return getTigerEval(state); } double v = -1000; State hypoState; foreach (AbstractMove m in moves) { hypoState = state.Clone(); m.ExecuteMove(hypoState); List<AbstractMove> newMoves = hypoState.findGoatMoves(); m.Value = minNoPrune(hypoState, (depthLimit - 1), newMoves); v = maximum(v, m.Value); } return v; }
public void TestStateCreated() { State s = new State(); Assert.IsNotNull(s); }
public void TestPlayersCreated() { State s = new State(); Assert.IsNotNull(s.Goat); Assert.AreEqual(s.Goat.GoatsInHand, 20); Assert.IsNotNull(s.Tiger); }
public override List<AbstractMove> FindMoves(State state) { List<AbstractMove> moves = getSlideandCaptureMoves(state, 'T'); return moves; }
public override void ExecuteMove(State state) { state.Board.SetState(EndSpace.GetRow(), EndSpace.GetColumn(), player.Symbol); ((Goat) player).DecrementGoatsInHand(); }
private String parseToString(AbstractMove m, State s) { StringBuilder result = new StringBuilder(); //result.Append(s.Board.GetBoardPic()); if (m == null) result.Append("null move!"); else { if (m.StartSpace == null) result.Append("99"); else { result.Append(m.StartSpace.GetRow()); result.Append(m.StartSpace.GetColumn()); } if (m.EndSpace == null) result.Append("null end Space!"); else { result.Append(m.EndSpace.GetRow()); result.Append(m.EndSpace.GetColumn()); } result.Append(m.Player.Symbol); if (m is TigerCaptureMove) { result.Append('c'); result.Append(((TigerCaptureMove)m).JumpSpace.GetRow()); result.Append(((TigerCaptureMove)m).JumpSpace.GetColumn()); } else if (m is GoatPlacementMove) result.Append('p'); else if (m is SlideMove) result.Append('s'); } return result.ToString(); }
public override List<AbstractMove> GetCaptureMoves(State state, List<CoordinatePair> adjacentSpaces, BoardSpace currSpace) { return null; }
protected double getTigerEval(State s) { Evaluation tEval = new TigerEvaluation(); return tEval.GetEvaluation(s); }
private List<AbstractMove> getPlacementMoves(State state) { List<AbstractMove> moves = new List<AbstractMove>(); for (int rowCounter = 0; rowCounter < 5; rowCounter++) { for (int columnCounter = 0; columnCounter < 5; columnCounter++) { if ((state.GetSpaceState(rowCounter, columnCounter)) == 'X') moves.Add(new GoatPlacementMove(null, state.Board.GetSpace(rowCounter, columnCounter), this)); } } return moves; }
private double minValue(State state, int depthLimit, List<AbstractMove> moves) { if (state.IsGoatGoalState() || state.IsTigerGoalState() || depthLimit == 0) { return getTigerEval(state); } double v = 1000; State hypoState; foreach (AbstractMove m in moves) { hypoState = state.Clone(); m.ExecuteMove(hypoState); List<AbstractMove> newMoves = hypoState.findTigerMoves(); m.Value = maxValue(hypoState, (depthLimit - 1), newMoves); v = minimum(v, m.Value); } if (v <= alpha) return v; beta = minimum(beta, v); return v; }
public State Clone() { Tiger t = tiger.Clone(); Goat g = goat.Clone(); Board newBoard = board.Clone(); State newState = new State(newBoard, g, t); return newState; }
public MinMaxPlayer(Tiger t, Goat g, State s) { state = s; board = s.Board; }