Esempio n. 1
0
        public override void calcAvailableMoves(PlayingPiece[,] board)
        {
            avaliableMoves.Clear();
            foreach (int[] dir in moveDirections)
            {
                int[] checkPos = new int[2] {
                    pos [0] + dir [0], pos [1] + dir [1]
                };

                SquareStatus square = getSquareState(board, checkPos);
                if (square == SquareStatus.outOfBounds)
                {
                    continue;
                }

                if (square == SquareStatus.empty)
                {
                    avaliableMoves.Add((int[])checkPos.Clone());
                }
                else if (board[checkPos[0], checkPos[1]].getColor() != playerColor)
                {
                    avaliableMoves.Add((int[])checkPos.Clone());
                }
            }
        }
Esempio n. 2
0
 public PlayingPiece[,] onPlayedOnPeasant(PlayingPiece[,] postBoard)
 {
     int[] enemyPos = getPos();
     enemyPos [1] += playerColor == Color.white ? -1 : 1;
     postBoard[enemyPos[0], enemyPos[1]] = null;
     return(postBoard);
 }
Esempio n. 3
0
        public void checkLongMoves(List <int[]> directions, PlayingPiece[,] board)
        {
            foreach (int[] dir in directions)
            {
                int[] checkPos = (int[])pos.Clone();
                checkPos [0] += dir [0];
                checkPos [1] += dir [1];
                SquareStatus square = getSquareState(board, checkPos);

                while (square != SquareStatus.outOfBounds)
                {
                    if (square == SquareStatus.occupied)
                    {
                        if (board [checkPos [0], checkPos [1]].getColor() != getColor())
                        {
                            avaliableMoves.Add((int[])checkPos.Clone());
                        }

                        break;
                    }


                    avaliableMoves.Add((int[])checkPos.Clone());

                    checkPos [0] += dir [0];
                    checkPos [1] += dir [1];
                    square        = getSquareState(board, checkPos);
                }
            }
        }
Esempio n. 4
0
        public SquareStatus getSquareState(PlayingPiece[,] board, int[] pos)
        {
            if (pos[0] < 0 || pos[0] >= 8 || pos[1] < 0 || pos[1] >= 8)
            {
                return(SquareStatus.outOfBounds);
            }

            return(board[pos[0], pos[1]] == null ? SquareStatus.empty : SquareStatus.occupied);
        }
Esempio n. 5
0
        private PlayingPiece[,] handlePawnSpecialls(PlayingPiece[,] postField, Move move, PlayingPiece movePiece)
        {
            if (Math.Abs(move.start [1] - move.target [1]) == 2)               //Played double step, give enpeasant!
            {
                (movePiece as Pawn).giveAnPeasant(postField);
            }

            if (move.start [0] != move.target [0])            //Played enpeasant! remove targetEnpeasant
            {
                postField = (movePiece as Pawn).onPlayedOnPeasant(postField);
            }

            return(postField);
        }
Esempio n. 6
0
        public static PlayingPiece[,] cloneField(PlayingPiece[,] board)
        {
            PlayingPiece[,] postField = new PlayingPiece[8, 8];
            for (int x = 0; x < 8; x++)
            {
                for (int y = 0; y < 8; y++)
                {
                    if (board [x, y] != null)
                    {
                        postField [x, y] = board [x, y].clone();
                    }
                }
            }

            return(postField);
        }
Esempio n. 7
0
        public Board playMove(Move move)
        {
            PlayingPiece[,] postField = cloneField(board);
            PlayingPiece movePiece = postField [move.start [0], move.start [1]];

            postField [move.start [0], move.start [1]]   = null;
            postField [move.target [0], move.target [1]] = movePiece;
            movePiece.setPos(move.target);
            movePiece.onPlayingMove();

            if (move.type == PieceType.pawn)
            {
                postField = handlePawnSpecialls(postField, move, movePiece);
            }


            return(new Board(postField));
        }
Esempio n. 8
0
        public override void calcAvailableMoves(PlayingPiece[,] board)
        {
            avaliableMoves.Clear();
            int yDir = playerColor == Color.white ? 1 : -1;

            //Forward Walk
            SquareStatus forwardSquare = getSquareState(board, new int[2] {
                pos[0], pos[1] + yDir
            });

            if (forwardSquare == SquareStatus.empty)
            {
                avaliableMoves.Add(new int[2] {
                    pos [0], pos [1] + yDir
                });
                //Double step
                if (canDoubleStep && getSquareState(board, new int[2] {
                    pos[0], pos[1] + yDir * 2
                }) == SquareStatus.empty)
                {
                    avaliableMoves.Add(new int[2] {
                        pos [0], pos [1] + yDir * 2
                    });
                }
            }

            //Attack Squares
            for (int x = -1; x < 2; x += 2)
            {
                int[]        checkPos = new int[] { pos [0] + x, pos [1] + yDir };
                SquareStatus square   = getSquareState(board, checkPos);
                if (square == SquareStatus.occupied && board[pos[0] + x, pos[1] + yDir].getColor() != playerColor)
                {
                    avaliableMoves.Add((int[])checkPos.Clone());
                }
            }

            //EnPeasant
            if (canEnPeasant)
            {
                avaliableMoves.Add(enPeasantPos);
                canEnPeasant = false;
            }
        }
Esempio n. 9
0
        public void giveAnPeasant(PlayingPiece[,] board)
        {
            for (int i = -1; i <= 1; i += 2)
            {
                int[] sidePos = new int[2] {
                    pos [0] + i, pos [1]
                };
                SquareStatus temp = getSquareState(board, sidePos);
                if (temp != SquareStatus.occupied)
                {
                    continue;
                }

                PlayingPiece p = board[sidePos[0], sidePos[1]];
                if (p.type != PieceType.pawn || p.getColor() == playerColor)
                {
                    continue;
                }

                (p as Pawn).enableEnPeasant(this);
            }
        }
Esempio n. 10
0
    internal void StartBoard()
    {
        PlayingPieces = new PlayingPiece[columns, rows];
        intGrid       = new int[columns, rows];

        gdesc = new int[columns, rows];
        float val = Mathf.Max((float)(columns), (float)(rows));

        if (!fillOnx)
        {
            step          = (Mathf.Abs(leftMark.transform.position.x) + Mathf.Abs(RightMark.transform.position.x)) / val;
            halfStep      = step / 2.0f;
            startPosition = new Vector3(leftMark.transform.position.x + halfStep, leftMark.transform.position.y - halfStep, zTilePosition);
        }
        else
        {
            Vector3 left  = Camera.main.ScreenToWorldPoint(new Vector3(0f, 0f, Camera.main.transform.position.z));
            Vector3 right = Camera.main.ScreenToWorldPoint(new Vector3(Mathf.Min((float)Screen.width, (float)Screen.height), 0f, Camera.main.transform.position.z));
            step          = (Mathf.Abs(left.x) + Mathf.Abs(right.x)) / val;
            halfStep      = step / 2.0f;
            startPosition = new Vector3(-(Mathf.Abs(left.x)) + halfStep, left.y - halfStep, zTilePosition);
        }

        float tileScale = (step * val) / (tile.GetComponent <Renderer>().bounds.size.x *val);

        if (!CentreOnx)
        {
            Vector3 realRight = Camera.main.ScreenToWorldPoint(new Vector3((float)Screen.width, 0f, Camera.main.transform.position.z));
            startPosition.x += Mathf.Abs(Mathf.Abs(realRight.x * 2f) - (step * columns)) / 2f;
        }

        generalScale = new Vector3(tileScale, tileScale, 1f);
        GridPositions.Init();

        //TextAsset TxTFile = (TextAsset)Resources.Load
        for (int y = 0; y < rows; y++)
        {
            for (int x = 0; x < columns; x++)
            {
                gdesc[x, y] = new int();
                if (DifficultyManagement.currentDifficulty < Difficulty.Four || x == 0 || x == columns - 1 || y == 0 || y == rows - 1)
                {
                    gdesc[x, y] = 1;
                }
                else
                {
                    if (DifficultyManagement.currentDifficulty >= Difficulty.Four && x > 0 && x < columns - 1 && y > 0 && y < rows - 1)
                    {
                        int tmp = Random.Range(1, 6);
                        gdesc[x, y] = 1 + tmp / 5;
                    }
                }
            }
        }
        for (int y = 0; y < rows; y++)
        {
            for (int x = 0; x < columns; x++)
            {
                float xp, yp = 0f;
                if (gdesc[x, y] != 0)
                {
                    xp = startPosition.x + (x * step);
                    yp = startPosition.y - (y * step);
                    GridPositions.SetPosition(x, y, xp, yp);
                    if (gdesc[x, y] != 99)
                    {
                        bool again = false;
                        do
                        {
                            int t = Random.Range(0, maxPieces);
                            int title;
                            if (DifficultyManagement.currentDifficulty < Difficulty.Three)
                            {
                                title = Random.Range(0, (int)DifficultyManagement.currentDifficulty + 1);
                            }
                            else
                            {
                                title = Random.Range(0, 4);
                            }
                            switch (gdesc[x, y])
                            {
                            case 1:
                                GetPiecesToUse(title);
                                PlayingPieces[x, y] = new PlayingPiece(Instantiate(piecesToUseNormal[t], new Vector3(xp, yp, zPiecePosition - Random.Range(20f, 30f)), Quaternion.identity) as GameObject, (PieceColor)title);
                                break;

                            case 2:
                                GetStrongPiecesToUse(title);
                                PlayingPieces[x, y] = new PlayingPiece(Instantiate(piecesToUseStrong[t], new Vector3(xp, yp, zPiecePosition - Random.Range(20f, 30f)), Quaternion.identity) as GameObject, (PieceColor)title);
                                break;
                            }

                            if (CheckTileMatchX(x, y, true) || CheckTileMatchY(x, y, true))
                            {
                                DestroyImmediate(PlayingPieces[x, y].Piece);
                                PlayingPieces[x, y] = null;
                                again = true;
                            }
                            else
                            {
                                again = false;
                            }
                        } while (again);
                        PlayingPieces[x, y].pieceScript.currentStrenght = (TileType)gdesc[x, y];
                        //PlayingPieces[x, y].pieceScript.MoveTo(x, y, zPiecePosition);
                        //PlayingPieces[x, y].Piece.transform.localScale = generalScale;
                    }
                }
            }
        }
        started = true;
    }
Esempio n. 11
0
 public abstract void calcAvailableMoves(PlayingPiece[,] board);
Esempio n. 12
0
 public Board(PlayingPiece[,] state)
 {
     board = state;
     initPlayerLists();
 }
Esempio n. 13
0
 public override void calcAvailableMoves(PlayingPiece[,] board)
 {
     avaliableMoves.Clear();
     checkLongMoves(moveDirections, board);
 }