public void A8ToString() { // Arrange var move = new Move("A8"); // Assert Assert.AreEqual("A8", move.ToString()); }
public void A9ToPos() { // Arrange var move = new Move("A8"); // Act int pos = move.Pos; // Assert Assert.AreEqual(7, pos); }
public void H1ToPos() { // Arrange var move = new Move("H1"); // Act int pos = move.Pos; // Assert Assert.AreEqual(56, pos); }
public void H1ToString() { // Arrange var move = new Move("H1"); // Assert Assert.AreEqual("H1", move.ToString()); }
/// <summary> /// Play a move. /// </summary> /// <param name="move">Move to play.</param> /// <returns>Board result after move has been played.</returns> /// <exception cref="ArgumentNullException">If move is null.</exception> /// <exception cref="ArgumentException">If move is invalid.</exception> public virtual Board Play(Move move) { if (move == null) { throw new ArgumentNullException("move"); } int pos = move.Pos; long opponent = ~(this.empty | this.mover); long cumulativeChange = 0; // up cumulativeChange |= scanDirection(pos, 8, opponent, p => p <= 63); // down cumulativeChange |= scanDirection(pos, -8, opponent, p => p >= 0); // left cumulativeChange |= scanDirection(pos, 1, opponent, p => p <= 63 && (p % 8) != 0); // right cumulativeChange |= scanDirection(pos, -1, opponent, p => p >= 0 && ((p + 1) % 8) != 0); // up-left cumulativeChange |= scanDirection(pos, 9, opponent, p => p <= 63 && (p % 8) != 0); // up-right cumulativeChange |= scanDirection(pos, 7, opponent, p => p <= 63 && ((p + 1) % 8 != 0)); // down-right cumulativeChange |= scanDirection(pos, -9, opponent, p => p >= 0 && ((p + 1) % 8) != 0); // down-left cumulativeChange |= scanDirection(pos, -7, opponent, p => p >= 0 && (p % 8) != 0); if (cumulativeChange == 0) { throw new ArgumentException("Invalid move", "move"); } long newEmpty = this.empty ^ (1L << move.Pos); long mover = opponent ^ cumulativeChange; return new Board(newEmpty.ToUInt64(), mover.ToUInt64(), this.color.Opponent()); }