Ejemplo n.º 1
0
        public List <Position> getMoves(Position pos, out int returnCode)
        {
            List <Position> listPos = new List <Position>();
            GridSpace       gs      = new GridSpace();

            gs = initialGrid.mainGrid[pos.row, pos.col];

            //check if it is not an unplayed grid space and that there is a piece on the space
            if (gs._piece != null && gs._isPlayable)
            {
                //check if the piece can move
                if (gs._piece.pieceCanMove)
                {
                    int max = 1;
                    if (gs._piece.pieceCanRun)
                    {
                        max = 10;
                    }

                    //find below positions
                    for (int i = pos.row + 1; i < pos.row + max + 1; i++)
                    {
                        if (i > 9 || !initialGrid.mainGrid[i, pos.col]._isPlayable)
                        {
                            break;
                        }
                        //make sure to stop before if same-team piece
                        if (initialGrid.mainGrid[i, pos.col]._piece != null && initialGrid.mainGrid[i, pos.col]._piece.piecePlayer.playerType == initialGrid.mainGrid[pos.row, pos.col]._piece.piecePlayer.playerType)
                        {
                            break;
                        }
                        Position p = new Position();
                        p.row = i;
                        p.col = pos.col;
                        listPos.Add(p);
                        if (initialGrid.mainGrid[i, pos.col]._piece != null)
                        {
                            break;
                        }
                    }

                    //find up positions
                    for (int i = pos.row - 1; i > pos.row - max - 1; i--)
                    {
                        if (i < 0 || !initialGrid.mainGrid[i, pos.col]._isPlayable)
                        {
                            break;
                        }
                        if (initialGrid.mainGrid[i, pos.col]._piece != null && initialGrid.mainGrid[i, pos.col]._piece.piecePlayer.playerType == initialGrid.mainGrid[pos.row, pos.col]._piece.piecePlayer.playerType)
                        {
                            break;
                        }
                        Position p = new Position();
                        p.row = i;
                        p.col = pos.col;
                        listPos.Add(p);
                        if (initialGrid.mainGrid[i, pos.col]._piece != null)
                        {
                            break;
                        }
                    }


                    //find left positions
                    for (int i = pos.col - 1; i > pos.col - max - 1; i--)
                    {
                        if (i < 0 || !initialGrid.mainGrid[pos.row, i]._isPlayable)
                        {
                            break;
                        }
                        if (initialGrid.mainGrid[pos.row, i]._piece != null && initialGrid.mainGrid[pos.row, i]._piece.piecePlayer.playerType == initialGrid.mainGrid[pos.row, pos.col]._piece.piecePlayer.playerType)
                        {
                            break;
                        }
                        Position p = new Position();
                        p.row = pos.row;
                        p.col = i;
                        listPos.Add(p);
                        if (initialGrid.mainGrid[pos.row, i]._piece != null)
                        {
                            break;
                        }
                    }

                    //find right positions
                    for (int i = pos.col + 1; i < pos.col + max + 1; i++)
                    {
                        if (i > 9 || !initialGrid.mainGrid[pos.row, i]._isPlayable)
                        {
                            break;
                        }
                        if (initialGrid.mainGrid[pos.row, i]._piece != null && initialGrid.mainGrid[pos.row, i]._piece.piecePlayer.playerType == initialGrid.mainGrid[pos.row, pos.col]._piece.piecePlayer.playerType)
                        {
                            break;
                        }
                        Position p = new Position();
                        p.row = pos.row;
                        p.col = i;
                        listPos.Add(p);
                        if (initialGrid.mainGrid[pos.row, i]._piece != null)
                        {
                            break;
                        }
                    }

                    returnCode = 1;
                }
                else
                {
                    //piece can't move
                    returnCode = 20;
                }
            }
            else
            {
                //not a piece
                returnCode = 30;
            }
            return(listPos);
        }
Ejemplo n.º 2
0
        public List<Position> getMoves(Position pos, out int returnCode)
        {
            List<Position> listPos = new List<Position>();
            GridSpace gs = new GridSpace();
            gs=initialGrid.mainGrid[pos.row,pos.col];

            //check if it is not an unplayed grid space and that there is a piece on the space
            if (gs._piece != null && gs._isPlayable)
            {
                //check if the piece can move
                if (gs._piece.pieceCanMove)
                {
                    int max = 1;
                    if (gs._piece.pieceCanRun) max = 10;

                    //find below positions
                    for (int i = pos.row + 1; i < pos.row + max + 1; i++)
                    {
                        if (i > 9 || !initialGrid.mainGrid[i, pos.col]._isPlayable) break;
                        //make sure to stop before if same-team piece
                        if (initialGrid.mainGrid[i, pos.col]._piece != null && initialGrid.mainGrid[i, pos.col]._piece.piecePlayer.playerType == initialGrid.mainGrid[pos.row, pos.col]._piece.piecePlayer.playerType) break;
                        Position p = new Position();
                        p.row = i;
                        p.col = pos.col;
                        listPos.Add(p);
                        if (initialGrid.mainGrid[i, pos.col]._piece != null) break;
                    }

                    //find up positions
                    for (int i = pos.row - 1; i > pos.row - max-1; i--)
                    {
                        if (i < 0 || !initialGrid.mainGrid[i, pos.col]._isPlayable) break;
                        if (initialGrid.mainGrid[i, pos.col]._piece != null && initialGrid.mainGrid[i, pos.col]._piece.piecePlayer.playerType == initialGrid.mainGrid[pos.row, pos.col]._piece.piecePlayer.playerType) break;
                        Position p = new Position();
                        p.row = i;
                        p.col = pos.col;
                        listPos.Add(p);
                        if (initialGrid.mainGrid[i, pos.col]._piece != null) break;

                    }

                    //find left positions
                    for (int i = pos.col - 1; i > pos.col - max - 1; i--)
                    {
                        if (i < 0 || !initialGrid.mainGrid[pos.row, i]._isPlayable) break;
                        if (initialGrid.mainGrid[pos.row, i]._piece != null && initialGrid.mainGrid[pos.row, i]._piece.piecePlayer.playerType == initialGrid.mainGrid[pos.row, pos.col]._piece.piecePlayer.playerType) break;
                        Position p = new Position();
                        p.row = pos.row;
                        p.col = i;
                        listPos.Add(p);
                        if (initialGrid.mainGrid[pos.row, i]._piece != null) break;

                    }

                    //find right positions
                    for (int i = pos.col + 1; i < pos.col + max + 1; i++)
                    {
                        if (i > 9 || !initialGrid.mainGrid[pos.row, i]._isPlayable) break;
                        if (initialGrid.mainGrid[pos.row, i]._piece != null && initialGrid.mainGrid[pos.row, i]._piece.piecePlayer.playerType == initialGrid.mainGrid[pos.row, pos.col]._piece.piecePlayer.playerType) break;
                        Position p = new Position();
                        p.row = pos.row;
                        p.col = i;
                        listPos.Add(p);
                        if (initialGrid.mainGrid[pos.row, i]._piece != null) break;

                    }

                    returnCode = 1;

                }
                else
                {
                    //piece can't move
                    returnCode = 20;
                }
            }
            else
            {
                //not a piece
                returnCode = 30;
            }
            return listPos;
        }