public void CowCanOnlyMoveToConnectedSpace() { int[] allMoves = new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23 }; for (int i = 0; i < 24; i++) { IBoard b = new Board(); ICowBox box = Substitute.For <ICowBox>(); box.TakeCow(Arg.Any <Color>()).Returns(new Cow(-1, Color.Red)); IReferee r = new Referee(b, box); b.Place(new Cow(-1, Color.Red), i); int[] ValidMoves = b.ConnectedSpaces(i); int[] inValidMoves = allMoves.Where(x => !ValidMoves.Contains(x)).ToArray(); foreach (int a in ValidMoves) { Assert.True(r.CanMove(Color.Red, i, a, Phase.Moving)); } foreach (int z in inValidMoves) { Assert.False(r.CanMove(Color.Red, i, z, Phase.Moving)); } } }
public bool Place(int position, IBoard board, IReferee referee, Phase currPhase) { if (referee.CanPlace(Color, position, currPhase)) { ICow cow = Box.TakeCow(Color); board.Place(cow, position); return(true); } else { return(false); } }
public void CowsCannotMoveDuringPlacement() { IBoard b = new Board(); ICowBox box = Substitute.For <ICowBox>(); box.TakeCow(Arg.Any <Color>()).Returns(new Cow(-1, Color.Red)); IPlayer p1 = new Player(Color.Red, box); IReferee r = new Referee(b, box); for (int i = 0; i < 23; i++) { p1.Place(i, b, r, Phase.Placing); int[] moves = b.ConnectedSpaces(i); foreach (int m in moves) { Assert.False(p1.Move(i, m, b, r, Phase.Placing)); } } }