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 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()); }
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; }
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; }