Ejemplo n.º 1
0
        private static List<BoardLocation> GetPossibleToLocations(Board board, BoardLocation fromLocation)
        {
            List<BoardLocation> possibleToLocations = new List<BoardLocation>();

            // always possible to pass
            possibleToLocations.Add(fromLocation);

            BoardLocation north = GetFirstNonEmptyInDirection(board, fromLocation, 0, -1);
            if (north != null && IsValidMove(board, fromLocation, north)) possibleToLocations.Add(north);

            BoardLocation south = GetFirstNonEmptyInDirection(board, fromLocation, 0, 1);
            if (south != null && IsValidMove(board, fromLocation, south)) possibleToLocations.Add(south);

            BoardLocation east = GetFirstNonEmptyInDirection(board, fromLocation, 1, 0);
            if (east != null && IsValidMove(board, fromLocation, east)) possibleToLocations.Add(east);

            BoardLocation west = GetFirstNonEmptyInDirection(board, fromLocation, -1, 0);
            if (west != null && IsValidMove(board, fromLocation, west)) possibleToLocations.Add(west);

            BoardLocation northWest = GetFirstNonEmptyInDirection(board, fromLocation, -1, -1);
            if (northWest != null && IsValidMove(board, fromLocation, northWest)) possibleToLocations.Add(northWest);

            BoardLocation southEast = GetFirstNonEmptyInDirection(board, fromLocation, 1, 1);
            if (southEast != null && IsValidMove(board, fromLocation, southEast)) possibleToLocations.Add(southEast);
            return possibleToLocations;
        }
Ejemplo n.º 2
0
        private static BoardLocation GetFirstNonEmptyInDirection(Board board, BoardLocation location, int directionX, int directionY)
        {
            int x = location.X;
            int y = location.Y;

            do
            {
                x += directionX;
                y += directionY;
            } while (BoardLocation.IsLegal(x, y) && (board.GetOwner(new BoardLocation(x, y)) == Player.None));

            if (!BoardLocation.IsLegal(x, y))
            {
                return null;
            }

            BoardLocation newLocation = new BoardLocation(x, y);
            if (newLocation == location ||
                board.GetOwner(newLocation) == Player.None)
            {
                return null;
            }
            else
            {
                return newLocation;
            }
        }
Ejemplo n.º 3
0
        public void SetSpace(BoardLocation location, Player owner, Stone stone, int height)
        {
            if (owner == Player.None)
            {
                throw new ArgumentException("owner not specified");
            }
            if (stone == Stone.None)
            {
                throw new ArgumentException("stone not specified");
            }
            if (height <= 0)
            {
                throw new ArgumentException("height not specified");
            }

            state[location.Y][location.X] = GetCode(owner, stone, height);
        }
Ejemplo n.º 4
0
 public Move(MoveType type, BoardLocation from, BoardLocation to)
 {
     this.type = type;
     this.from = from;
     this.to = to;
 }
Ejemplo n.º 5
0
 public Stone GetStone(BoardLocation location)
 {
     return GetStone(state[location.Y][location.X]);
 }
Ejemplo n.º 6
0
 public Player GetOwner(BoardLocation location)
 {
     return GetOwner(state[location.Y][location.X]);
 }
Ejemplo n.º 7
0
 public int GetHeight(BoardLocation location)
 {
     return GetHeight(state[location.Y][location.X]);
 }
Ejemplo n.º 8
0
 public void ClearSpace(BoardLocation location)
 {
     state[location.Y][location.X] = Empty;
 }
Ejemplo n.º 9
0
 private static bool IsValidMove(Board board, BoardLocation from, BoardLocation to)
 {
     Player fromOwner = board.GetOwner(from);
     Player toOwner = board.GetOwner(to);
     int fromHeight = board.GetHeight(from);
     int toHeight = board.GetHeight(to);
     return (fromOwner != Player.None) &&
         (toOwner != Player.None) &&
         (fromOwner == toOwner || fromHeight >= toHeight);
 }