예제 #1
0
        public void undoMove(Move move)
        {
            int   xFrom  = move.getFrom()[0];
            int   yFrom  = move.getFrom()[1];
            int   xTo    = move.getTo()[0];
            int   yTo    = move.getTo()[1];
            short player = -1;

            //get current player
            if (fields[xTo, yTo] == GameVar.FIELD_WHITE)
            {
                player = GameVar.PLAYER_WHITE;
            }
            else if (fields[xTo, yTo] == GameVar.FIELD_BLACK)
            {
                player = GameVar.PLAYER_BLACK;
            }

            //swith from/to fields
            if (xFrom != xTo || yFrom != yTo)       //do not swith if jump is cycle
            {
                fields[xFrom, yFrom] = fields[xTo, yTo];
                fields[xTo, yTo]     = GameVar.FIELD_EMPTY;
            }

            if (player != -1)
            {
                removePlayerField(xTo, yTo, player);
                addPlayerField(xFrom, yFrom, player);

                //undo fields removed
                ArrayList fieldsRemoved = move.getRemoveFields();
                if (fieldsRemoved != null)
                {
                    int x = 0;
                    int y = 0;
                    for (int i = 0; i < fieldsRemoved.Count; i++)
                    {
                        x = (int)(fieldsRemoved[i] as Array).GetValue(0);
                        y = (int)(fieldsRemoved[i] as Array).GetValue(1);
                        if (player == GameVar.PLAYER_WHITE)
                        {
                            addPlayerField(x, y, GameVar.PLAYER_BLACK);
                            fields[x, y] = GameVar.PLAYER_BLACK;
                        }
                        else if (player == GameVar.PLAYER_BLACK)
                        {
                            addPlayerField(x, y, GameVar.PLAYER_WHITE);
                            fields[x, y] = GameVar.PLAYER_WHITE;
                        }
                    }
                }
            }
        }
예제 #2
0
        private void boardMakeMove(Move move)
        {
            PictureBox piece_start = pieces[move.getFrom()[0], move.getFrom()[1]];
            PictureBox piece_end   = pieces[move.getTo()[0], move.getTo()[1]];
            int        player      = desk.getPieceOwnership(move.getFrom()[0], move.getFrom()[1]);

            piece_end.BackgroundImage   = piece_start.BackgroundImage;
            piece_start.BackgroundImage = null;
            changePlayerPieces(move.getRemoveFields(), rules.getOppositePlayer((short)player));
            addGameNotice((player == GameVar.PLAYER_WHITE ? playerWhiteName.Text : playerBlackName.Text) + " moves " + Coords.getCoordsStr(move));
        }
예제 #3
0
        private void boardUnmakeMove(Move move)
        {
            PictureBox piece_start       = pieces[move.getFrom()[0], move.getFrom()[1]];
            PictureBox piece_end         = pieces[move.getTo()[0], move.getTo()[1]];
            bool       restoreOriginalBg = true;
            int        player            = desk.getPieceOwnership(move.getTo()[0], move.getTo()[1]);

            piece_start.BackgroundImage = piece_end.BackgroundImage;
            piece_end.BackgroundImage   = null;
            changePlayerPieces(move.getRemoveFields(), rules.getOppositePlayer((short)player), restoreOriginalBg);
            addGameNotice("move canceled " + Coords.getCoordsStr(move) + " by " + (player == GameVar.PLAYER_WHITE ? playerWhiteName.Text : playerBlackName.Text));
        }
예제 #4
0
        public static String getCoordsStr(Move move, bool compactOutput = false)
        {
            String output = getCoordsStr(move.getFrom()[0], move.getFrom()[1]);

            if (!compactOutput)
            {
                ArrayList fieldsOver    = move.getOverFields();
                int       fieldsOverLen = fieldsOver.Count;
                for (int i = 0; i < fieldsOverLen; i++)
                {
                    output += " " + getCoordsStr((int)(fieldsOver[i] as Array).GetValue(0), (int)(fieldsOver[i] as Array).GetValue(1));
                }
            }
            return(output + " " + getCoordsStr(move.getTo()[0], move.getTo()[1]));
        }
예제 #5
0
        public bool isEqual(Move move)
        {
            if (from[0] != move.getFrom()[0] || from[1] != move.getFrom()[1])
            {
                return(false);
            }
            if (to[0] != move.getTo()[0] || to[1] != move.getTo()[1])
            {
                return(false);
            }

            ArrayList moveFields = move.getOverFields();
            int       fieldsCnt  = over.Count;

            if (fieldsCnt != moveFields.Count)
            {
                return(false);
            }
            for (int i = 0; i < fieldsCnt; i++)
            {
                if (((int[])over[i])[0] != ((int[])moveFields[i])[0] || ((int[])over[i])[1] != ((int[])moveFields[i])[1])
                {
                    return(false);
                }
            }

            moveFields = move.getRemoveFields();
            fieldsCnt  = remove.Count;
            if (fieldsCnt != moveFields.Count)
            {
                return(false);
            }
            for (int i = 0; i < fieldsCnt; i++)
            {
                if (((int[])remove[i])[0] != ((int[])moveFields[i])[0] || ((int[])remove[i])[1] != ((int[])moveFields[i])[1])
                {
                    return(false);
                }
            }
            return(true);
        }
예제 #6
0
        private void highlightMove(Move move)
        {
            ArrayList overFields      = move.getOverFields();
            ArrayList removeFields    = move.getRemoveFields();
            String    pieceEndStr     = null;
            int       overFieldsLen   = overFields.Count;
            int       removeFieldsLen = removeFields.Count;
            int       i;

            drawPictureBoxControl(pieces[move.getFrom()[0], move.getFrom()[1]], Properties.Resources.piece_control_select); // start piece
            for (i = 0; i < overFieldsLen; i++)                                                                             // pieces jumped over in multi-jump
            {
                drawPictureBoxControl(pieces[(int)(overFields[i] as Array).GetValue(0), (int)(overFields[i] as Array).GetValue(1)], Properties.Resources.piece_control_select, (i + 1).ToString());
            }
            for (i = 0; i < removeFieldsLen; i++)          // pieces removed
            {
                drawPictureBoxControl(pieces[(int)(removeFields[i] as Array).GetValue(0), (int)(removeFields[i] as Array).GetValue(1)], Properties.Resources.piece_control_error);
            }
            if (overFieldsLen > 0)      // add number for end piece if multi-jump
            {
                pieceEndStr = i.ToString();
            }
            drawPictureBoxControl(pieces[move.getTo()[0], move.getTo()[1]], Properties.Resources.piece_control_select, pieceEndStr);     // end piece
        }
예제 #7
0
        public void makeMove(Move move)
        {
            int   xFrom  = move.getFrom()[0];
            int   yFrom  = move.getFrom()[1];
            int   xTo    = move.getTo()[0];
            int   yTo    = move.getTo()[1];
            short player = -1;

            //get current player
            if (fields[xFrom, yFrom] == GameVar.FIELD_WHITE)
            {
                player = GameVar.PLAYER_WHITE;
            }
            else if (fields[xFrom, yFrom] == GameVar.FIELD_BLACK)
            {
                player = GameVar.PLAYER_BLACK;
            }
            else
            {
                throw new Exception("Making move from empty field");
            }

            //check remove fields
            ArrayList removeFields = move.getRemoveFields();

            if (removeFields == null)
            {
                return;
            }

            //remove fields - fields that were jumped
            int x = 0;
            int y = 0;
            int removeFieldsCnt = removeFields.Count;

            for (int i = 0; i < removeFieldsCnt; i++)
            {
                x = (int)(removeFields[i] as Array).GetValue(0);
                y = (int)(removeFields[i] as Array).GetValue(1);
                if (fields[x, y] == GameVar.FIELD_WHITE && player == GameVar.PLAYER_BLACK)
                {
                    removePlayerField(x, y, GameVar.PLAYER_WHITE);
                }
                else if (fields[x, y] == GameVar.FIELD_BLACK && player == GameVar.PLAYER_WHITE)
                {
                    removePlayerField(x, y, GameVar.PLAYER_BLACK);
                }
                if (x != xTo || y != yTo)         //make sure field where jump landed is not removed
                {
                    fields[x, y] = GameVar.FIELD_EMPTY;
                }
            }

            //switch from/to fields of current player
            removePlayerField(xFrom, yFrom, player);
            addPlayerField(xTo, yTo, player);

            //switch from/to fields on desk
            if (xFrom != xTo || yFrom != yTo)       //do not swith in case circular jumps
            {
                fields[move.getTo()[0], move.getTo()[1]]     = fields[move.getFrom()[0], move.getFrom()[1]];
                fields[move.getFrom()[0], move.getFrom()[1]] = GameVar.FIELD_EMPTY;
            }
        }