Beispiel #1
0
 //node constructors
 public Node(Node p, Move m, int a, int b)
 {
     //create a new board with the move provided
     CBoard = Move.CopyAndMove(p.CBoard, m);
     Alpha = a;
     Beta = b;
 }
Beispiel #2
0
        public Board(int boardSize = DefaultBoardSize)
        {
            VerifyBoardSizeOrThrow(boardSize);

            _boardSize = boardSize;
            _pieces = new Piece[boardSize, boardSize];
        }
Beispiel #3
0
 //construct node from just a board state
 public Node(Piece[,] b)
 {
     Parent = null;
     CBoard = b;
     Alpha = int.MinValue;
     Beta = int.MaxValue;
 }
Beispiel #4
0
            public Board(int _width, int _height)
            {
                width = _width;
                height = _height;

                internalBoard = new Piece[width, height];
            }
Beispiel #5
0
 public Board()
 {
     bBoard = new Piece[bWidth,bHeight];
     for (int i = 0; i < BHeight; i++)
     {
         for (int j = 0; j < BWidth; j++)
         {
             bBoard[i, j] = new Piece();
         }
     }
     ActivePieces = new Piece[16];
     ActivePieces[0] = new Piece(1, 1, 1, 1);
     ActivePieces[1] = new Piece(1, 1, 1, 0);
     ActivePieces[2] = new Piece(1, 1, 0, 1);
     ActivePieces[3] = new Piece(1, 1, 0, 0);
     ActivePieces[4] = new Piece(1, 0, 1, 1);
     ActivePieces[5] = new Piece(1, 0, 1, 0);
     ActivePieces[6] = new Piece(1, 0, 0, 1);
     ActivePieces[7] = new Piece(1, 0, 0, 0);
     ActivePieces[8] = new Piece(0, 1, 1, 1);
     ActivePieces[9] = new Piece(0, 1, 1, 0);
     ActivePieces[10] = new Piece(0, 1, 0, 1);
     ActivePieces[11] = new Piece(0, 1, 0, 0);
     ActivePieces[12] = new Piece(0, 0, 1, 1);
     ActivePieces[13] = new Piece(0, 0, 1, 0);
     ActivePieces[14] = new Piece(0, 0, 0, 1);
     ActivePieces[15] = new Piece(0, 0, 0, 0);
 }
Beispiel #6
0
 public Board(Board b)
 {
     this.board = (Piece[,])b.board.Clone();
     this.State = b.State;
     this.CurrentColor = b.CurrentColor;
     this.CurrentTurn = b.CurrentTurn;
     lastMoves = new Stack<PreviousMove>();
 }
Beispiel #7
0
	public Board(int width, int height)
	{
		this.width = width;
		this.height = height;
		pieces = new Piece[width,height];
		for(int x = 0; x < width; x++) {
			for(int y = 0; y < height; y++) {
				pieces[x,y] = null;
			}
		}
	}
Beispiel #8
0
	public Board(Board old)
	{
		width = old.width;
		height = old.height;
		pieces = new Piece[width, height];
		for(int x = 0; x < width; x++) {
			for(int y = 0; y < height; y++) {
				pieces[x,y] = old.pieces[x,y] == null ? null : new Piece(old.pieces[x,y]);
			}
		}
	}
        private void ClearTable()
        {
            // initiaize table model
            _tablePieces = new Piece[8, 8];

            // initialize Drag & Drop Manager
            _ddManager.ClearSources();
            _ddManager.ClearTargets();

            // create Checkers Table
            CreateTable();
        }
Beispiel #10
0
 public Board()
 {
     board = new Piece[8, 8];
     WhiteCastle = Castle.NoneCastle;
     BlackCastle = Castle.NoneCastle;
     Side = Color.White;
     EnPassantSquare = new Coordinate(0, 0);//means deactive
     boardStateHistory = new Stack<State>();
     SetUpBoard();
     zobrist=new Zobrist(this);
     threeFoldRepetetion = new ThreeFoldRepetition();
 }
        /**
         * @brief 初期化
         */
        protected void Start()
        {
            Skin.Name = skinName;

            Board.Size = boardSize;

            pieces = new Piece[Board.Size.row, Board.Size.col];

            for (int i = 0; i < Board.Size.col; ++i)
            {
                pieces[8, i] = Piece.Build(new Grid(8, i));
            }
        }
Beispiel #12
0
 public void Copy(Board board)
 {
     this.board = new Piece[8, 8];
     this.turn = board.GetTurn();
     this.playerColour = board.GetPlayerColour();
     this.ai = board.GetAIState();
     for (int i = 0; i < 8; i++)
         for (int j = 0; j < 8; j++) {
             if (board.GetPiece(i, j) != null) {
                 if (board.GetPiece(i, j).IsDux())
                     this.board[i, j] = new Dux(board.GetPiece(i, j).GetColour());
                 else
                     this.board[i, j] = new Pawn(board.GetPiece(i, j).GetColour());
             }
             else
                 this.board[i, j] = null;
         }
 }
Beispiel #13
0
 public Board(Board oBoard)
 {
     bBoard = new Piece[4, 4];
         for (int i = 0; i < BHeight; i++)
         {
             for (int j = 0; j < BWidth; j++)
             {
                 bBoard[i, j] = new Piece(oBoard.BBoard[i, j].color,
                                          oBoard.BBoard[i, j].height,
                                          oBoard.BBoard[i, j].shape,
                                          oBoard.BBoard[i, j].full);
             }
         }
         ActivePieces = new Piece[oBoard.activePieces.Length];
         for (int i = 0; i < oBoard.activePieces.Length; ++i)
         {
             ActivePieces[i] = new Piece(oBoard.ActivePieces[i].height, oBoard.ActivePieces[i].color, oBoard.ActivePieces[i].shape, oBoard.ActivePieces[i].full);
         }
         SelectedPiece = oBoard.SelectedPiece;
 }
	public void CreateGrid (int rows, int columns, float spacing = 0.1f) {

		this.rows = rows;
		this.columns = columns;

		grid = new Piece[columns,rows];

		for(int y = 0; y < rows; ++y) {
			for (int x = 0; x < columns; ++x) {

				// piece knows its location
				var piece = Prefabs.CreateRandomPiece (x,y);

				// position within scene
				piece.gameObject.transform.parent = transform;

				// position within grid
				grid[x,y] = piece;
			}
		};
	}
Beispiel #15
0
        public override List <Coordonates> GetUsableCoordonates(Coordonates Piece_coordonates, Piece[,] Board)
        {
            List <Coordonates> coords = new List <Coordonates>();

            for (int i = -1; i < 2; i++)
            {
                for (int j = -1; j < 2; j++)
                {
                    if (!new Coordonates(Piece_coordonates.x + i, Piece_coordonates.y + j).OutOfBoard() && (Board[Piece_coordonates.x + i, Piece_coordonates.y + j] == null || Board[Piece_coordonates.x + i, Piece_coordonates.y + j].color != Board[Piece_coordonates.x, Piece_coordonates.y].color))
                    {
                        coords.Add(new Coordonates(Piece_coordonates.x + i, Piece_coordonates.y + j));
                    }
                }
            }
            return(coords);
        }
Beispiel #16
0
        public override List <Coord> GetPossibleMoves(Piece[,] Gameboard, Coord coord)
        {
            List <Coord> coords = new List <Coord>();
            Color        ColorAdversaire;
            int          n = 1;
            int          m = 1;
            int          o = 1;
            int          p = 1;
            int          q = 1;
            int          r = 1;
            int          s = 1;
            int          t = 1;

            if (color == Color.noir)
            {
                ColorAdversaire = Color.blanc;
            }
            else
            {
                ColorAdversaire = Color.noir;
            }

            Piece CaseMouvement = Gameboard[coord.x, coord.y];
            Piece CaseAtk1;
            Piece CaseAtk2;
            Piece CaseAtk3;
            Piece CaseAtk4;
            Piece CaseAtk5;
            Piece CaseAtk6;
            Piece CaseAtk7;
            Piece CaseAtk8;

            //La reine a les deplacements de la tour + du fou
            //droite
            while (coord.y + n < 8 && coord.y + n >= 0)
            {
                CaseAtk1 = Gameboard[coord.x, coord.y + n];
                if (CaseAtk1 == null || (CaseAtk1 != null && CaseAtk1.color == ColorAdversaire))
                {
                    coords.Add(new Coord(coord.x, coord.y + n));
                }
                n++;
            }
            //gauche
            while (coord.y - m < 8 && coord.y - m >= 0)
            {
                CaseAtk2 = Gameboard[coord.x, coord.y - m];
                if (CaseAtk2 == null || (CaseAtk2 != null && CaseAtk2.color == ColorAdversaire))
                {
                    coords.Add(new Coord(coord.x, coord.y - m));
                }
                m++;
            }
            //bas
            while (coord.x + o < 8 && coord.x + o >= 0)
            {
                CaseAtk3 = Gameboard[coord.x + o, coord.y];
                if (CaseAtk3 == null || CaseAtk3 != null && CaseAtk3.color == ColorAdversaire)
                {
                    coords.Add(new Coord(coord.x + o, coord.y));
                }
                o++;
            }
            //haut
            while (coord.x - p < 8 && coord.x - p >= 0)
            {
                CaseAtk4 = Gameboard[coord.x - p, coord.y];
                if (CaseAtk4 == null || CaseAtk4 != null && CaseAtk4.color == ColorAdversaire)
                {
                    coords.Add(new Coord(coord.x - p, coord.y));
                }
                p++;
            }
            //Diagonale haut droite
            while (coord.y + q < 8 && coord.y + q >= 0 && coord.x + q < 8 && coord.x + q >= 0)
            {
                CaseAtk5 = Gameboard[coord.x + q, coord.y + q];
                if (CaseAtk5 == null || (CaseAtk5 != null && CaseAtk5.color == ColorAdversaire))
                {
                    coords.Add(new Coord(coord.x + q, coord.y + q));
                }
                q++;
            }
            //Diagonale haut gauche
            while (coord.y - r < 8 && coord.y - r >= 0 && coord.x - r < 8 && coord.x - r >= 0)
            {
                CaseAtk6 = Gameboard[coord.x - r, coord.y - r];
                if (CaseAtk6 == null || (CaseAtk6 != null && CaseAtk6.color == ColorAdversaire))
                {
                    coords.Add(new Coord(coord.x - r, coord.y - r));
                }
                r++;
            }
            //Diagonale bas gauche
            while (coord.x + s < 8 && coord.x + s >= 0 && coord.y - s < 8 && coord.y - s >= 0)
            {
                CaseAtk7 = Gameboard[coord.x + s, coord.y - s];
                if (CaseAtk7 == null || CaseAtk7 != null && CaseAtk7.color == ColorAdversaire)
                {
                    coords.Add(new Coord(coord.x + s, coord.y - s));
                }
                s++;
            }
            //Diagoname bas droite
            while (coord.x - t < 8 && coord.x - t >= 0 && coord.x + t < 8 && coord.x + t >= 0)
            {
                CaseAtk8 = Gameboard[coord.x - t, coord.y + t];
                if (CaseAtk8 == null || CaseAtk8 != null && CaseAtk8.color == ColorAdversaire)
                {
                    coords.Add(new Coord(coord.x - t, coord.y + t));
                }
                t++;
            }
            return(coords);
        }
Beispiel #17
0
 // Methods
 public void Start(BoardSize boardSize)
 {
     Int32 size = (Int32) boardSize;
     board = new Piece[size, size];
     if(started)
     {
         Stop();
     }
     started = true;
 }
Beispiel #18
0
    /// <summary>
    /// Get the adjacent piece in the given direction
    /// </summary>
    /// <param name="piece"></param>
    /// <param name="direction"></param>
    /// <returns>
    /// Pair of adjacent piece in the given direction (null if tile is empty or out of bounds), and its position
    /// </returns>
    public static KeyValuePair <Piece, Vector2> GetAdjacentPiece(Piece[,] board, Piece piece, TileDirection direction)
    {
        Vector2 tile;
        var     x   = (int)piece.Position.x;
        var     y   = (int)piece.Position.y;
        var     odd = y % 2 != 0;

        switch (direction)
        {
        case TileDirection.Left:
            tile = new Vector2(x - 1, y);
            break;

        case TileDirection.TopLeft:
            tile = new Vector2(x - 1, y + 1);
            if (odd)
            {
                tile.x += 1;
            }
            break;

        case TileDirection.TopRight:
            tile = new Vector2(x, y + 1);
            if (odd)
            {
                tile.x += 1;
            }
            break;

        case TileDirection.Right:
            tile = new Vector2(x + 1, y);
            //possible = true;
            break;

        case TileDirection.BottomRight:
            tile = new Vector2(x, y - 1);
            if (odd)
            {
                tile.x += 1;
            }
            break;

        case TileDirection.BottomLeft:
            tile = new Vector2(x - 1, y - 1);
            if (odd)
            {
                tile.x += 1;
            }
            break;

        default:
            throw new ArgumentOutOfRangeException("direction", direction, null);
        }

        int x2 = (int)tile.x, y2 = (int)tile.y;
        var pos = new Vector2(x2, y2);

        return(InBounds(board, tile)
            ? new KeyValuePair <Piece, Vector2>(board[x2, y2], pos)
            : new KeyValuePair <Piece, Vector2>(null, pos));
    }
Beispiel #19
0
 public Board()
 {
     this.board = new Piece[HEIGHT, WIDTH];
     this.State = BoardState.Unknown;
     lastMoves = new Stack<PreviousMove>();
 }
 public void deserialize(char[,] bArr)
 {
     /*
      * [[r,k,m,a,g,a,m,k,r],
      *  [ , , , , , , , , ],
      *  [ ,c, , , , , ,c, ],
      *  [p, ,p, ,p, ,p, ,p],
      *  [ , , , , , , , , ],
      *  [ , , , , , , , , ],
      *  [P, ,P, ,P, ,P, ,P],
      *  [ ,C, , , , , ,C, ],
      *  [ , , , , , , , , ],
      *  [R,K,M,A,G,A,M,K,R]]
      */
     this.pieces = new Piece[10, 9];
     for (int i = 0; i < 10; i++)
     {
         for (int j = 0; j < 9; j++)
         {
             Piece p = _getPiece(bArr[i, j]);
             if (p != null)
                 p.setCurrentPosition(new Position(i, j));
             this.pieces[i, j] = p;
         }
     }
 }
Beispiel #21
0
 public Loader(String filename)
 {
     _board = new Piece[8, 8];
 }
Beispiel #22
0
 /// <summary>
 /// 盤面の初期配列をセットする。
 /// </summary>
 public BoardState()
 {
     this.board     = GetInitBoard();
     this.turnPiece = Piece.Black;
 }
Beispiel #23
0
 public Board()
 {
     Pieces = new Piece[8, 8];
 }
Beispiel #24
0
 public Board(int rows, int columns)
 {
     Rows    = rows;
     Columns = columns;
     pieces  = new Piece[rows, columns];
 }
Beispiel #25
0
    public override bool ValidMove(Piece[,] board, int x1, int y1, int x2, int y2)
    {
        int deltaMove  = Mathf.Abs(x1 - x2);
        int deltaMoveY = Mathf.Abs(y2 - y1);

        int currentX = x1;
        int currentY = y1 + 1;

        if ((deltaMove == 0) && (deltaMoveY != 0))
        {
            if ((y1 - y2) < 0)
            {
                Debug.Log("Gora");
                for (int i = 0; i < deltaMoveY - 1; i++)
                {
                    if (board[currentX, currentY] != null)
                    {
                        Debug.Log("Cant move");
                        return(false);
                    }
                    currentY++;
                }
                return(this.CanKill(board, x2, y2));
            }
            if ((y1 - y2) > 0)
            {
                currentX = x1;
                currentY = y1 - 1;
                Debug.Log("Dol");
                for (int i = 0; i < deltaMoveY - 1; i++)
                {
                    if (board[currentX, currentY] != null)
                    {
                        Debug.Log("Cant move");
                        return(false);
                    }
                    currentY--;
                }
                return(this.CanKill(board, x2, y2));
            }
        }
        if ((deltaMove != 0) && (deltaMoveY == 0))
        {
            if ((x1 - x2) < 0)
            {
                currentY = y1;
                currentX = x1 + 1;
                Debug.Log("Prawo");
                for (int i = 0; i < deltaMove - 1; i++)
                {
                    if (board[currentX, currentY] != null)
                    {
                        Debug.Log("Cant move");
                        return(false);
                    }
                    currentX++;
                }
                return(this.CanKill(board, x2, y2));
            }
            if ((x1 - x2) > 0)
            {
                Debug.Log("Lewo");
                currentY = y1;
                currentX = x1 - 1;
                for (int i = 0; i < deltaMove - 1; i++)
                {
                    if (board[currentX, currentY] != null)
                    {
                        Debug.Log("Cant move");
                        return(false);
                    }
                    currentX--;
                }
                return(this.CanKill(board, x2, y2));
            }
        }
        return(false);
    }
Beispiel #26
0
 public virtual List <Coord> GetUsuableCoordinates(Coord PieceCoord, Piece[,] Board)
 {
     return(new List <Coord>());
 }
Beispiel #27
0
 public void PrintAcceptedMove(Piece[,] currentBoard)
 {
     Console.WriteLine("\nMove accepted, here's the current board:\n");
     PrintBoard(currentBoard);
 }
Beispiel #28
0
 public Board()
 {
     this.board = new Piece[8, 8];
     PlacePieces();
 }
Beispiel #29
0
 public BoardGame(int lines, int columns)
 {
     Lines   = lines;
     Columns = columns;
     Pieces  = new Piece[Lines, Columns];
 }
Beispiel #30
0
        public override List <Coord> GetPossibleMoves(Piece[,] GameBoard, Coord coord)
        {
            List <Coord> listCoord = new List <Coord>();

            Color ColorAdversary;
            int   SensMovement;

            if (color == Color.black)
            {
                ColorAdversary = Color.white;
                SensMovement   = 1;
            }
            else
            {
                ColorAdversary = Color.black;
                SensMovement   = -1;
            }

            Piece CaseMovement1 = null, CaseMovement2 = null, CaseAtk1 = null, CaseAtk2 = null;

            if (IsFirst)
            {
                if (IsInGameBoard(coord.x, coord.y + SensMovement * 2))
                {
                    CaseMovement2 = GameBoard[coord.x, coord.y + SensMovement * 2];
                }
                if (CaseMovement2 == null && IsInGameBoard(coord.x, coord.y + SensMovement * 2))
                {
                    listCoord.Add(new Coord(coord.x, coord.y + SensMovement * 2));
                }
            }

            if (IsInGameBoard(coord.x, coord.y + SensMovement))
            {
                CaseMovement1 = GameBoard[coord.x, coord.y + SensMovement];
            }
            if (IsInGameBoard(coord.x + 1, coord.y + SensMovement))
            {
                CaseAtk1 = GameBoard[coord.x + 1, coord.y + SensMovement];
            }
            if (IsInGameBoard(coord.x - 1, coord.y + SensMovement))
            {
                CaseAtk2 = GameBoard[coord.x - 1, coord.y + SensMovement];
            }

            if (CaseMovement1 == null && IsInGameBoard(coord.x, coord.y + SensMovement))
            {
                listCoord.Add(new Coord(coord.x, coord.y + SensMovement));
            }

            if (CaseAtk1 != null && CaseAtk1.color == ColorAdversary)
            {
                listCoord.Add(new Coord(coord.x + 1, coord.y + SensMovement));
            }

            if (CaseAtk2 != null && CaseAtk2.color == ColorAdversary)
            {
                listCoord.Add(new Coord(coord.x - 1, coord.y + SensMovement));
            }

            if (listCoord.Count == 0)
            {
                return(null);
            }

            return(listCoord);
            //TODO return valid positions fot the piece
        }
Beispiel #31
0
        public override List <Coord> GetPossibleMoves(Piece[,] GameBoard, Coord coord)
        {
            List <Coord> coords = new List <Coord>();

            Color ColorAdversary;

            if (c == Color.black)
            {
                ColorAdversary = Color.white;
            }
            else
            {
                ColorAdversary = Color.black;
            }


            if (coord.x > 1 && coord.y < 7)
            {
                Piece MoveTopLeft = GameBoard[coord.x - 1, coord.y + 2];
                if (MoveTopLeft == null || MoveTopLeft != null && MoveTopLeft.c == ColorAdversary)
                {
                    coords.Add(new Coord(coord.x - 1, coord.y + 2));
                }
            }

            if (coord.x < 8 && coord.y < 7)
            {
                Piece MoveTopRight = GameBoard[coord.x + 1, coord.y + 2];
                if (MoveTopRight == null || MoveTopRight != null && MoveTopRight.c == ColorAdversary)
                {
                    coords.Add(new Coord(coord.x + 1, coord.y + 2));
                }
            }


            if (coord.x > 2 && coord.y < 8)
            {
                Piece MoveLeftTop = GameBoard[coord.x - 2, coord.y + 1];
                if (MoveLeftTop == null || MoveLeftTop != null && MoveLeftTop.c == ColorAdversary)
                {
                    coords.Add(new Coord(coord.x - 2, coord.y + 1));
                }
            }
            if (coord.x > 2 && coord.y > 1)
            {
                Piece MoveLeftBack = GameBoard[coord.x - 2, coord.y - 1];
                if (MoveLeftBack == null || MoveLeftBack != null && MoveLeftBack.c == ColorAdversary)
                {
                    coords.Add(new Coord(coord.x - 2, coord.y - 1));
                }
            }


            if (coord.x > 1 && coord.y > 2)
            {
                Piece MoveBackLeft = GameBoard[coord.x - 1, coord.y - 2];
                if (MoveBackLeft == null || MoveBackLeft != null && MoveBackLeft.c == ColorAdversary)
                {
                    coords.Add(new Coord(coord.x - 1, coord.y - 2));
                }
            }
            if (coord.x < 8 && coord.y > 2)
            {
                Piece MoveBackRight = GameBoard[coord.x + 1, coord.y - 2];
                if (MoveBackRight == null || MoveBackRight != null && MoveBackRight.c == ColorAdversary)
                {
                    coords.Add(new Coord(coord.x + 1, coord.y - 2));
                }
            }


            if (coord.x < 7 && coord.y < 8)
            {
                Piece MoveRightTop = GameBoard[coord.x + 2, coord.y + 1];
                if (MoveRightTop == null || MoveRightTop != null && MoveRightTop.c == ColorAdversary)
                {
                    coords.Add(new Coord(coord.x + 2, coord.y + 1));
                }
            }
            if (coord.x < 7 && coord.y > 1)
            {
                Piece MoveRightBack = GameBoard[coord.x + 2, coord.y - 1];
                if (MoveRightBack == null || MoveRightBack != null && MoveRightBack.c == ColorAdversary)
                {
                    coords.Add(new Coord(coord.x + 2, coord.y - 1));
                }
            }

            return(coords);
        }
Beispiel #32
0
        /// <summary>
        /// Create new Array[8,8] for a Board and put pieces on it
        /// </summary>
        private void PopulateBoard()
        {
            _Board = new Piece[8, 8];

            _Board[0, 0] = new Piece(PieceType.Rook, PlayerColor.White);
            _Board[0, 1] = new Piece(PieceType.Knight, PlayerColor.White);
            _Board[0, 2] = new Piece(PieceType.Bishop, PlayerColor.White);
            _Board[0, 3] = new Piece(PieceType.Queen, PlayerColor.White);
            _Board[0, 4] = new Piece(PieceType.King, PlayerColor.White);
            _Board[0, 5] = new Piece(PieceType.Bishop, PlayerColor.White);
            _Board[0, 6] = new Piece(PieceType.Knight, PlayerColor.White);
            _Board[0, 7] = new Piece(PieceType.Rook, PlayerColor.White);

            _Board[7, 0] = new Piece(PieceType.Rook, PlayerColor.Black);
            _Board[7, 1] = new Piece(PieceType.Knight, PlayerColor.Black);
            _Board[7, 2] = new Piece(PieceType.Bishop, PlayerColor.Black);
            _Board[7, 3] = new Piece(PieceType.Queen, PlayerColor.Black);
            _Board[7, 4] = new Piece(PieceType.King, PlayerColor.Black);
            _Board[7, 5] = new Piece(PieceType.Bishop, PlayerColor.Black);
            _Board[7, 6] = new Piece(PieceType.Knight, PlayerColor.Black);
            _Board[7, 7] = new Piece(PieceType.Rook, PlayerColor.Black);

            for (int i = 0; i < 8; i++)
            {
                _Board[1, i] = new Piece(PieceType.Pawn, PlayerColor.White);
                _Board[6, i] = new Piece(PieceType.Pawn, PlayerColor.Black);
            }
        }
 private void _initialize()
 {
     this.pieces = new Piece[10, 9];
     _initializeBlackSide();
     _initializeRedSide();
 }
Beispiel #34
0
 public Board(Player currentPlayer, Piece[,] boardState = null)
 {
     _board         = boardState ?? new Piece[GameSettings.BoardSize, GameSettings.BoardSize];
     CurrentPlayer  = currentPlayer;
     CapturedPieces = new List <Piece>();
 }
Beispiel #35
0
 public virtual List <Coord> GetPossibleMoves(Piece[,] GameBoard, Coord coord)
 {
     return(new List <Coord>());
 }
Beispiel #36
0
 public void OnGameStart()
 {
     Piece[,] pieces = model.Pieces;
     CreateTiles(pieces);
     CreateSelf();
 }
Beispiel #37
0
        public double Score(Board board, bool useNeurons)
        {
            var input = new double[8, 8];

            //Flip a copy of the board to always have self at bottom for scoring purposes
            Piece[,] temp = Serializer.DeepClone(board.Pieces);

            /*if (player.IsW) { temp = Serializer.DeepClone(board.Pieces); }
             * else { temp = ArrayInverse(board.Pieces); }*/
            for (int i = 0; i < 8; i++)
            {
                for (int ii = 0; ii < 8; ii++)
                {
                    //Set piece values equal to standard chess piece values
                    Piece p = temp[i, ii];
                    //Don't have to set empty piece = 0 b/c array initialization does it automatically
                    if (p is Empty)
                    {
                        continue;
                    }
                    if (p is Pawn)
                    {
                        input[i, ii] = 1;
                    }
                    if (p is Knight || p is Bishop)
                    {
                        input[i, ii] = 3;
                    }
                    if (p is Rook)
                    {
                        input[i, ii] = 5;
                    }
                    if (p is Queen)
                    {
                        input[i, ii] = 9;
                    }
                    if (p is King)
                    {
                        input[i, ii] = 15;
                    }

                    //Set opposite color piece values to negative
                    if (p.Player.IsW != player.IsW)
                    {
                        input[i, ii] *= -1;
                    }
                }
            }
            if (useNeurons)
            {
                //Normalize everything
                input = ActivationFunctions.Normalize(input, 8, 8);
                return(Run(input));
            }
            //Count the value of pieces left on the board
            else
            {
                int sum = 0;
                foreach (int i in input)
                {
                    sum += i;
                }
                return(sum);
            }
        }
Beispiel #38
0
 public abstract void showPossible(Piece[,] board, int sx, int sy);
Beispiel #39
0
 public void Stop()
 {
     if(!started)
     {
         return;
     }
     for(int i = 0; i != board.GetLength(0); ++i)
     {
         for(int j = 0; j != board.GetLength(1); ++j)
         {
             if(board[i, j] != null)
             {
                 board[i, j].Kill();
             }
         }
     }
     board = null;
     started = false;
 }
Beispiel #40
0
 public abstract void Move(Piece[,] board, int sx, int sy, int dx, int dy);
Beispiel #41
0
 public Board(Loader loader)
 {
     _grid = loader.Board;
 }
Beispiel #42
0
 public Turn(Piece[,] board, Piece turnPiece)
 {
     this.board     = board;
     this.turnPiece = turnPiece;
 }
Beispiel #43
0
 public void Reset()
 {
     _board = new Piece[3, 3] { { Piece.Empty, Piece.Empty, Piece.Empty},
                                { Piece.Empty, Piece.Empty, Piece.Empty},
                                { Piece.Empty, Piece.Empty, Piece.Empty} };
 }
Beispiel #44
0
        /// <summary>Clears the board and places the initial pieces</summary>
        public void ClearBoard()
        {
            // Create an array of pieces where all pieces are set to Piece.None
            pieces = new Piece[WIDTH, HEIGHT];
            for(int x = 0; x < WIDTH; ++x)
                for(int y = 0; y < HEIGHT; ++y)
                    pieces[x, y] = Piece.None;

            // Place the initial pieces in the middle of the board
            pieces[WIDTH / 2 - 1, HEIGHT / 2 - 1] = Piece.Blue;
            pieces[WIDTH / 2, HEIGHT / 2 - 1] = Piece.Red;
            pieces[WIDTH / 2 - 1, HEIGHT / 2] = Piece.Red;
            pieces[WIDTH / 2, HEIGHT / 2] = Piece.Blue;

            // Initialize a new game status
            currStatus = new GameStatus();
            currStatus.currTurn = Board.Piece.Red;
            currStatus.score = new int[2] {2,2};
            currStatus.gameEnded = false;
            currStatus.showHints = true;
        }
Beispiel #45
0
 public abstract void UpdateSupportingPieces(Piece[,] board, Piece piece, SupportingPiece[,] supportingPieces);
Beispiel #46
0
 public ReadOnlyBoard(Piece[,] board)
 {
     _board = board;
 }
Beispiel #47
0
 public abstract List <Move> GetValidMoves(Piece[,] board, Piece piece);
Beispiel #48
0
 public King(bool isWhite, int x, int y, Piece[,] piece) : base(isWhite, x, y, piece)
 {
     id     = 'K';
     symbol = this.isWhite ? '♔' : '♚';
 }
Beispiel #49
0
		private void InitializeBoard(QF.Board board, IEngine playerX, IEngine playerO)
		{
			int x = 0, y = 0;

			if (this.pieces != null)
			{
				for (x = 0; x < QF.Board.Dimension; x++)
				{
					for (y = 0; y < QF.Board.Dimension; y++)
					{
						if (this.pieces[x, y] != null)
						{
							this.Controls.Remove(this.pieces[x, y]);
						}
					}
				}
			}

			this.source = null;
			this.playerX = playerX;
			this.playerO = playerO;

			if (board == null)
			{
				this.board = new QF.Board();
			}
			else
			{
				this.board = board;
			}

			this.pieces = new Piece[QF.Board.Dimension, QF.Board.Dimension];

			for (x = 0; x < QF.Board.Dimension; x++)
			{
				for (y = 0; y < QF.Board.Dimension; y++)
				{
					Point point = new Point(x, y);
					Piece newPiece = new Piece(new QF.Piece(point, this.board.GetPiece(point)));
					newPiece.Selected += this.OnPieceSelected;

					this.pieces[x, y] = newPiece;
					this.Controls.Add(newPiece);
				}
			}

			this.UpdatePieceStates();
		}
    public bool IsForceToMove(Piece[,] board, int x, int y)
    {
        if (isWhite || isKing)
        {
            // Top left
            if (x >= 2 && y <= 5)
            {
                Piece p = board[x - 1, y + 1];
                // If there is a piece, and it is not the same color as ours
                if (p != null && p.isWhite != isWhite)
                {
                    // Check if its possible to land after the jump
                    if (board[x - 2, y + 2] == null)
                    {
                        return(true);
                    }
                }
            }
            // Top right

            if (x <= 5 && y <= 5)
            {
                Piece p = board[x + 1, y + 1];
                // If there is a piece, and it is not the same color as ours
                if (p != null && p.isWhite != isWhite)
                {
                    // Check if its possible to land after the jump
                    if (board[x + 2, y + 2] == null)
                    {
                        return(true);
                    }
                }
            }
        }
        if (!isWhite || isKing)
        {
            // Bottom left
            if (x >= 2 && y >= 2)
            {
                Piece p = board[x - 1, y - 1];
                // If there is a piece, and it is not the same color as ours
                if (p != null && p.isWhite != isWhite)
                {
                    // Check if its possible to land after the jump
                    if (board[x - 2, y - 2] == null)
                    {
                        return(true);
                    }
                }
            }
            // Bottom right

            if (x <= 5 && y >= 2)
            {
                Piece p = board[x + 1, y - 1];
                // If there is a piece, and it is not the same color as ours
                if (p != null && p.isWhite != isWhite)
                {
                    // Check if its possible to land after the jump
                    if (board[x + 2, y - 2] == null)
                    {
                        return(true);
                    }
                }
            }
        }

        return(false);
    }
Beispiel #51
0
    /// <summary>
    /// Sprawdzanie czy figura musi wykonać ruch
    /// </summary>
    /// <param name="p">tablica figur</param>
    /// <param name="x">położenie figury w poziomie></param>
    /// <param name="y">położenie figury w pionie></param>
    public bool IsForceToMove(Piece[,] board, int x, int y)
    {
        if (isWhite || isKing)
        {
            //Góra lewo
            if (x >= 2 && y <= 5)
            {
                Piece p = board[x - 1, y + 1];
                //Jeżeli figura jest innego koloru niż nasza
                if (p != null && p.isWhite != isWhite)
                {
                    //Sprawdź czy można wylądować za figurą przy zbiciu
                    if (board[x - 2, y + 2] == null)
                    {
                        return(true);
                    }
                }
            }

            // Góra prawo
            if (x <= 5 && y <= 5)
            {
                Piece p = board[x + 1, y + 1];
                //Jeżeli figura jest innego koloru niż nasza
                if (p != null && p.isWhite != isWhite)
                {
                    //Sprawdź czy można wylądować za figurą przy zbiciu
                    if (board[x + 2, y + 2] == null)
                    {
                        return(true);
                    }
                }
            }
        }

        if (!isWhite || isKing)
        {
            //Dół lewo
            if (x >= 2 && y >= 2)
            {
                Piece p = board[x - 1, y - 1];
                //Jeżeli figura jest innego koloru niż nasza
                if (p != null && p.isWhite != isWhite)
                {
                    //Sprawdź czy można wylądować za figurą przy zbiciu
                    if (board[x - 2, y - 2] == null)
                    {
                        return(true);
                    }
                }
            }

            // Dół prawo
            if (x <= 5 && y >= 2)
            {
                Piece p = board[x + 1, y - 1];
                //Jeżeli figura jest innego koloru niż nasza
                if (p != null && p.isWhite != isWhite)
                {
                    //Sprawdź czy można wylądować za figurą przy zbiciu
                    if (board[x + 2, y - 2] == null)
                    {
                        return(true);
                    }
                }
            }
        }
        return(false);
    }
Beispiel #52
0
 public Board(int lines, int colluns)
 {
     this.lines  = lines;
     this.coluns = colluns;
     this.pieces = new Piece[lines, colluns];
 }
Beispiel #53
0
 public void InitBoard()
 {
     Board = new Piece[ShogiEnvironment.Board_X, ShogiEnvironment.Board_Y];
     PieceCounters = new int[ShogiEnvironment.Player.Count, CountPlys.Length];
     PieceCounter = 0;
 }
Beispiel #54
0
 public AiConfig(Piece[,] board, Piece turnPiece, string aiName)
 {
     PieceList = GetPieceList(board);
     TurnPiece = turnPiece;
     AiName    = aiName;
 }
Beispiel #55
0
        public Move findBestMoveForCurrentPlayerNoDoUndo(int sec)
        {
            Move m0 = null, result = null;

            if (this.CurrentTurn < 2 && this.CurrentColor == Piece.Color.White) {
                if (rand.Next(1, 10) <= 3)
                    return new Move("a2-a3");
                return new Move("b2-b3");
            }
            if (this.CurrentTurn < 2 && this.CurrentColor == Piece.Color.Black) {
                if (lastMoves.Count > 0) {
                    PreviousMove pm = lastMoves.Pop();
                    switch (pm.Move.ToString()) {
                        case "a2-a3":
                        case "d2-d3":
                            m0 = new Move("d5-d4");
                            break;
                        default:
                            m0 = new Move("a5-a4");
                            break;
                    }
                    lastMoves.Push(pm);
                    return m0;
                }
            }
            if (!cache.HasLoadedFile) {
                cache.TryASyncLoad();
            }
            TimeSpan t = TimeSpan.FromSeconds(sec);
            int d0 = 2, a0 = 0, v0 = 0, v = 0, negaresult = 0;

            List<Move> moves = this.getMoves(this.CurrentColor);
            DateTime start = DateTime.Now;
            Board board;
            while (t > DateTime.Now - start) {
                a0 = -100000;
                v = -100000;

                foreach (Move m in moves) {
                    if (t < DateTime.Now - start) {
                        if (result == null) //if we didn't even have time to evaluate one level down, panic and just pick one.
                            result = m;
                        Console.WriteLine("Depth: {0}", d0);
                        return result;
                    }
                    board = new Board(this);
                    if (board.makeMove(m)) {
                        if (board.State != BoardState.Playing) {
                            if (board.State == BoardState.BlackWinner || board.State == BoardState.WhiteWinner) {
                                Console.WriteLine("Depth: {0}", d0);
                                return m; //this move is a winner, pick it!
                            }
                        }
                        negaresult = AI.negaMaxNodoUndo(board, d0, -100000, -a0, (t - (DateTime.Now - start)).TotalSeconds);
                        v0 = Math.Max(v, -negaresult);
                        a0 = Math.Max(a0, v0);
                        if (v0 >= v)
                            m0 = m;
                        v = Math.Max(v, v0);
                    }
                }
                ++d0;
                result = m0;
            }
            Console.WriteLine("Depth: {0}", d0);
            return result;
        }
Beispiel #56
0
        public override List <byte[][]> GetAttack(Piece[,] board)
        {
            // Assume cannot move
            List <byte[][]> moves = new List <byte[][]>();

            byte[] pos = GetPos(board);

            // Queen's movement
            for (byte seed = 0; seed < 8; seed++)
            {
                sbyte dX     = (sbyte)(((seed + 2) % 3) - 1);
                sbyte dY     = (sbyte)((((seed / 3) + 2) % 3) - 1);
                int[] newPos = { (pos[0] + dX), (pos[1] + dY) };


                while (0 <= newPos[0] && newPos[0] < board.GetLength(0) && 0 <= newPos[1] && newPos[1] < board.GetLength(1))
                {
                    if (board[newPos[0], newPos[1]] != null)
                    {
                        if (board[newPos[0], newPos[1]].team != this.team)
                        {
                            byte[][] move = new byte[3][];
                            move[0] = new byte[] { (byte)newPos[0], (byte)newPos[1], byte.MaxValue, byte.MaxValue };
                            move[1] = new byte[] { (byte)newPos[0], (byte)newPos[1], pos[0], pos[1] };
                            move[2] = new byte[] { pos[0], pos[1], byte.MaxValue, byte.MaxValue - 1 };
                            moves.Add(move);
                        }
                        break;
                    }

                    newPos[0] += dX;
                    newPos[1] += dY;
                }
            }

            // Knight's movement
            for (byte seed = 0; seed < 8; seed++)
            {
                byte[] dir   = { (byte)(((seed / 4) + 1) % 2), (byte)(seed / 4) };
                sbyte  xSign = (sbyte)((((seed / 2) % 2) * 2) - 1);
                sbyte  ySign = (sbyte)(((seed % 2) * 2) - 1);

                byte[] finalDir = { (byte)(pos[0] + (dir[0] + 1) * xSign), (byte)(pos[1] + (dir[1] + 1) * ySign) };
                if (finalDir[0] < 0 || finalDir[0] >= board.GetLength(0) || finalDir[1] < 0 || finalDir[1] >= board.GetLength(1))
                {
                    continue;
                }
                if (board[finalDir[0], finalDir[1]] != null)
                {
                    if (board[finalDir[0], finalDir[1]].team != this.team)
                    {
                        byte[][] steps = new byte[3][];
                        steps[0] = new byte[] { finalDir[0], finalDir[1], byte.MaxValue, byte.MaxValue };
                        steps[1] = new byte[] { finalDir[0], finalDir[1], pos[0], pos[1] };
                        steps[2] = new byte[] { pos[0], pos[1], byte.MaxValue, byte.MaxValue - 1 };
                        moves.Add(steps);
                    }
                }
            }

            return(moves);
        }
Beispiel #57
0
 public GamePanel(byte i_Size)
 {
     r_Size  = i_Size;
     m_Board = new Piece[r_Size, r_Size];
 }
Beispiel #58
0
 public Board(int lines, int rows)
 {
     this.Lines = lines;
     this.Rows  = rows;
     pieces     = new Piece[lines, rows];
 }
Beispiel #59
0
 public Board(int width, int heigth)
 {
     this.Width = width;
     this.Height = heigth;
     BoardMatrix = new Piece[width, heigth];
 }
Beispiel #60
0
 private void CreateGrid()
 {
     grid = new Piece[BOARD_SIZE, BOARD_SIZE];
 }