Пример #1
0
        public void Reset()
        {
            for (var y = 0; y < 8; y++)
            {
                for (var x = 0; x < 8; x++)
                {
                    Squares[x, y] = 0;
                }
            }

            Squares[3, 3] = 2;
            Squares[4, 3] = 1;
            Squares[3, 4] = 1;
            Squares[4, 4] = 2;

            LastMove = new PlaceDiscResult(PlayerColor.None, -1, -1, false, null);
        }
Пример #2
0
        public PlaceDiscResult TryPlaceDisc(PlayerColor playerColor, int x, int y)
        {
            bool isMoveValid;
            var  discsToFlip = new List <int[]>();

            if (!AreCoordinatesInBounds(x, y) || Squares[x, y] != 0)
            {
                isMoveValid = false;
            }
            else
            {
                var otherPlayerColor = playerColor == PlayerColor.Black ? PlayerColor.White : PlayerColor.Black;

                CheckDirection(playerColor, otherPlayerColor, x, y, 0, -1, discsToFlip);   // Up
                CheckDirection(playerColor, otherPlayerColor, x, y, 1, -1, discsToFlip);   // Up-right
                CheckDirection(playerColor, otherPlayerColor, x, y, 1, 0, discsToFlip);    // Right
                CheckDirection(playerColor, otherPlayerColor, x, y, 1, 1, discsToFlip);    // Down-right
                CheckDirection(playerColor, otherPlayerColor, x, y, 0, 1, discsToFlip);    // Down
                CheckDirection(playerColor, otherPlayerColor, x, y, -1, 1, discsToFlip);   // Down-left
                CheckDirection(playerColor, otherPlayerColor, x, y, -1, 0, discsToFlip);   // Left
                CheckDirection(playerColor, otherPlayerColor, x, y, -1, -1, discsToFlip);  // Up-left

                isMoveValid = discsToFlip.Any();
            }

            if (isMoveValid)
            {
                Squares[x, y] = (int)playerColor;

                foreach (var discToFlip in discsToFlip)
                {
                    Squares[discToFlip[0], discToFlip[1]] = (int)playerColor;
                }
            }

            var result = new PlaceDiscResult(playerColor, x, y, isMoveValid, discsToFlip.ToArray());

            if (isMoveValid)
            {
                LastMove = result;
            }

            return(result);
        }