Inheritance: Token
Ejemplo n.º 1
0
        private void movecontrol_Pawn(Pawn t)
        {
            int po_x = t.getX();
            int po_y = t.getY();
            possiblemove.Clear();
            if (t.getSide() == "b")
            {
                if (po_y < 7)
                {
                    if (t_map[getIndex(po_x, po_y + 1)] == null)
                    {
                        possiblemove.Add(new Point(po_x, po_y + 1));
                        if (t.isFirstmove())
                        {
                            if (po_y < 6 && t_map[getIndex(po_x, po_y + 2)] == null)
                                possiblemove.Add(new Point(po_x, po_y + 2));
                        }
                    }

                    if (po_x>0 && t_map[getIndex(po_x - 1, po_y + 1)] != null && t_map[getIndex(po_x - 1, po_y + 1)].getSide() == "w")
                    {
                        possiblemove.Add(new Point(po_x - 1, po_y + 1));
                    }

                    if (po_x<7 && t_map[getIndex(po_x + 1, po_y + 1)] != null && t_map[getIndex(po_x + 1, po_y + 1)].getSide() == "w")
                    {
                        possiblemove.Add(new Point(po_x + 1, po_y + 1));
                    }
                    if (enPassant != null && enPassant.getSide() != t.getSide() && enPassant.getY() == po_y && Math.Abs(enPassant.getX() - po_x) == 1)
                    {
                        possiblemove.Add(new Point(enPassant.getX(), enPassant.getY() + 1));
                    }
                }
            }
            else
            {
                if (po_y > 0)
                {
                    if (t_map[getIndex(po_x, po_y - 1)] == null)
                    {
                        possiblemove.Add(new Point(po_x, po_y - 1));
                        if (t.isFirstmove())
                        {
                            if (po_y > 1 && t_map[getIndex(po_x, po_y - 2)] == null)
                                possiblemove.Add(new Point(po_x, po_y - 2));
                        }
                    }

                    if (po_x>0 && t_map[getIndex(po_x - 1, po_y - 1)] != null && t_map[getIndex(po_x - 1, po_y - 1)].getSide() == "b")
                    {
                        possiblemove.Add(new Point(po_x - 1, po_y - 1));
                    }
                    if (po_x<7 && t_map[getIndex(po_x + 1, po_y - 1)] != null && t_map[getIndex(po_x + 1, po_y - 1)].getSide() == "b")
                    {
                        possiblemove.Add(new Point(po_x + 1, po_y - 1));
                    }
                    if (enPassant != null && enPassant.getSide() != t.getSide() && enPassant.getY() == po_y && Math.Abs(enPassant.getX() - po_x) == 1)
                    {
                        possiblemove.Add(new Point(enPassant.getX(), enPassant.getY() - 1));
                    }
                }
            }
        }
Ejemplo n.º 2
0
        private void initTokens()
        {
            for (int i = 0; i < 64; i++)
            {
                t_map[i] = null;
            }
            //castle
            t_map[getIndex(0, 0)] = new Castle(0, 0, "b", Resources.Castle_b_l, Resources.Castle_b_d, Resources.Castle_b_l_p, Resources.Castle_b_d_p, Resources.Castle_b_l_s, Resources.Castle_b_d_s);
            t_map[getIndex(7, 0)] = new Castle(7, 0, "b", Resources.Castle_b_l, Resources.Castle_b_d, Resources.Castle_b_l_p, Resources.Castle_b_d_p, Resources.Castle_b_l_s, Resources.Castle_b_d_s);

            t_map[getIndex(0, 7)] = new Castle(0, 7, "w", Resources.Castle_w_l, Resources.Castle_w_d, Resources.Castle_w_l_p, Resources.Castle_w_d_p, Resources.Castle_w_l_s, Resources.Castle_w_d_s);
            t_map[getIndex(7, 7)] = new Castle(7, 7, "w", Resources.Castle_w_l, Resources.Castle_w_d, Resources.Castle_w_l_p, Resources.Castle_w_d_p, Resources.Castle_w_l_s, Resources.Castle_w_d_s);

            //Knight
            t_map[getIndex(1, 0)] = new Knight(1, 0, "b", Resources.Knight_b_l, Resources.Knight_b_d, Resources.Knight_b_l_p, Resources.Knight_b_d_p, Resources.Knight_b_l_s, Resources.Knight_b_d_s);
            t_map[getIndex(6, 0)] = new Knight(6, 0, "b", Resources.Knight_b_l, Resources.Knight_b_d, Resources.Knight_b_l_p, Resources.Knight_b_d_p, Resources.Knight_b_l_s, Resources.Knight_b_d_s);

            t_map[getIndex(1, 7)] = new Knight(1, 7, "w", Resources.Knight_w_l, Resources.Knight_w_d, Resources.Knight_w_l_p, Resources.Knight_w_d_p, Resources.Knight_w_l_s, Resources.Knight_w_d_s);
            t_map[getIndex(6, 7)] = new Knight(6, 7, "w", Resources.Knight_w_l, Resources.Knight_w_d, Resources.Knight_w_l_p, Resources.Knight_w_d_p, Resources.Knight_w_l_s, Resources.Knight_w_d_s);
            //Bishop
            t_map[getIndex(2, 0)] = new Bishop(2, 0, "b", Resources.Bishop_b_l, Resources.Bishop_b_d, Resources.Bishop_b_l_p, Resources.Bishop_b_d_p, Resources.Bishop_b_l_s, Resources.Bishop_b_d_s);
            t_map[getIndex(5, 0)] = new Bishop(5, 0, "b", Resources.Bishop_b_l, Resources.Bishop_b_d, Resources.Bishop_b_l_p, Resources.Bishop_b_d_p, Resources.Bishop_b_l_s, Resources.Bishop_b_d_s);

            t_map[getIndex(2, 7)] = new Bishop(2, 7, "w", Resources.Bishop_w_l, Resources.Bishop_w_d, Resources.Bishop_w_l_p, Resources.Bishop_w_d_p, Resources.Bishop_w_l_s, Resources.Bishop_w_d_s);
            t_map[getIndex(5, 7)] = new Bishop(5, 7, "w", Resources.Bishop_w_l, Resources.Bishop_w_d, Resources.Bishop_w_l_p, Resources.Bishop_w_d_p, Resources.Bishop_w_l_s, Resources.Bishop_w_d_s);

            //Queen
            t_map[getIndex(3, 0)] = new Queen(3, 0, "b", Resources.Queen_b_l, Resources.Queen_b_d, Resources.Queen_b_l_p, Resources.Queen_b_d_p, Resources.Queen_b_l_s, Resources.Queen_b_d_s);

            t_map[getIndex(3, 7)] = new Queen(3, 7, "w", Resources.Queen_w_l, Resources.Queen_w_d, Resources.Queen_w_l_p, Resources.Queen_w_d_p, Resources.Queen_w_l_s, Resources.Queen_w_d_s);

            //King
            t_map[getIndex(4, 0)] = new King(4, 0, "b", Resources.King_b_l, Resources.King_b_d, Resources.King_b_l_p, Resources.King_b_d_p, Resources.King_b_l_s, Resources.King_b_d_s);

            t_map[getIndex(4, 7)] = new King(4, 7, "w", Resources.King_w_l, Resources.King_w_d, Resources.King_w_l_p, Resources.King_w_d_p, Resources.King_w_l_s, Resources.King_w_d_s);

            //Pawn
            for (int i = 0; i < 8; i++)
            {
                t_map[getIndex(i, 1)] = new Pawn(i, 1, "b", Resources.Pawn_b_l, Resources.Pawn_b_d, Resources.Pawn_b_l_p, Resources.Pawn_b_d_p, Resources.Pawn_b_l_s, Resources.Pawn_b_d_s);
                t_map[getIndex(i, 6)] = new Pawn(i, 6, "w", Resources.Pawn_w_l, Resources.Pawn_w_d, Resources.Pawn_w_l_p, Resources.Pawn_w_d_p, Resources.Pawn_w_l_s, Resources.Pawn_w_d_s);
            }
        }