Example #1
0
 //verifies if there exists a viable jump move for the pawn
 public int jump()
 {
     if (x + 2 < 8 && y + 2 < 8)
     {
         if (board.get_square(x + 2, y + 2) == 0 && board.get_square(x + 1, y + 1) == 3 - side)
         {
             return(1);
         }
     }
     if (x - 2 > -1 && y + 2 < 8)
     {
         if (board.get_square(x - 2, y + 2) == 0 && board.get_square(x - 1, y + 1) == 3 - side)
         {
             return(1);
         }
     }
     if (x + 2 < 8 && y - 2 > -1)
     {
         if (board.get_square(x + 2, y - 2) == 0 && board.get_square(x + 1, y - 1) == 3 - side)
         {
             return(1);
         }
     }
     if (x - 2 > -1 && y - 2 > -1)
     {
         if (board.get_square(x - 2, y - 2) == 0 && board.get_square(x - 1, y - 1) == 3 - side)
         {
             return(1);
         }
     }
     return(0);
 }
Example #2
0
        //handle first pawn selection, then move from mouseclicks
        void MoveHandler(object sender, EventArgs e)
        {
            int            result = 0;
            DraughtsButton field  = (DraughtsButton)sender;

            switch (phase)
            {
            case 0:         //choose the pawn
                if (state.get_square(field.x, field.y) == state.active_side)
                {
                    field.FlatStyle = FlatStyle.Flat;
                    field.FlatAppearance.BorderColor = Color.DarkGreen;
                    field.FlatAppearance.BorderSize  = 2;
                    highlighted = field;
                    phase       = 1;
                    move_list.Enqueue(field.x);
                    move_list.Enqueue(field.y);
                }
                break;

            case 1:                                                          //make the move or change the pawn
                if (state.get_square(field.x, field.y) == state.active_side) //change the pawn
                {
                    highlighted.FlatAppearance.BorderSize = 0;
                    highlighted.FlatStyle            = System.Windows.Forms.FlatStyle.Flat;
                    field.FlatStyle                  = FlatStyle.Flat;
                    field.FlatAppearance.BorderColor = Color.DarkGreen;
                    field.FlatAppearance.BorderSize  = 2;
                    highlighted = field;
                    move_list.Dequeue();
                    move_list.Dequeue();
                    move_list.Enqueue(field.x);
                    move_list.Enqueue(field.y);
                }
                else
                {
                    if (state.get_square(field.x, field.y) == 0)
                    {
                        result = state.move(highlighted.x, highlighted.y, field.x, field.y);
                        switch (result)
                        {
                        //0 - incorrect move, no action neccessary, so no case
                        case 1:        //end turn;
                            move_list.Enqueue(field.x);
                            move_list.Enqueue(field.y);
                            if (state.check_promotion(field.x, field.y))
                            {
                                if (state.active_side == 1)
                                {
                                    field.Image = Properties.Resources.white_king;
                                }
                                else
                                {
                                    field.Image = Properties.Resources.black_king;
                                }
                            }
                            else
                            {
                                field.Image = highlighted.Image;
                            }
                            field.id          = highlighted.id;
                            highlighted.Image = Properties.Resources.field;
                            highlighted.id    = 0;
                            highlighted.FlatAppearance.BorderSize = 0;
                            highlighted.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
                            phase = 0;
                            change_active();
                            break;

                        case 2:        //remove captured pawn and end turn
                            jump = true;
                            move_list.Enqueue(field.x);
                            move_list.Enqueue(field.y);
                            winCheck();
                            if (state.check_promotion(field.x, field.y))
                            {
                                if (state.active_side == 1)
                                {
                                    field.Image = Properties.Resources.white_king;
                                }
                                else
                                {
                                    field.Image = Properties.Resources.black_king;
                                }
                            }
                            else
                            {
                                field.Image = highlighted.Image;
                            }
                            field.id          = highlighted.id;
                            highlighted.Image = Properties.Resources.field;
                            highlighted.id    = 0;
                            highlighted.FlatAppearance.BorderSize = 0;
                            ((DraughtsButton)this.Controls.Find(state.to_kill, false)[0]).Image = Properties.Resources.field;
                            highlighted.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
                            phase = 0;
                            change_active();
                            break;

                        case 3:        //further captures possible
                            jump = true;
                            winCheck();
                            move_list.Enqueue(field.x);
                            move_list.Enqueue(field.y);
                            if (state.check_promotion(field.x, field.y))
                            {
                                if (state.active_side == 1)
                                {
                                    field.Image = Properties.Resources.white_king;
                                }
                                else
                                {
                                    field.Image = Properties.Resources.black_king;
                                }
                            }
                            else
                            {
                                field.Image = highlighted.Image;
                            }
                            field.id = highlighted.id;
                            field.FlatAppearance.BorderColor = Color.DarkGreen;
                            field.FlatAppearance.BorderSize  = 2;
                            highlighted.Image = Properties.Resources.field;
                            ((DraughtsButton)this.Controls.Find(state.to_kill, false)[0]).Image = Properties.Resources.field;
                            highlighted.id = 0;
                            highlighted.FlatAppearance.BorderSize = 0;
                            highlighted.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
                            highlighted           = field;
                            phase = 2;
                            break;
                        }
                    }
                }
                break;

            case 2:    //move continuation after a jump
                result = state.move(highlighted.x, highlighted.y, field.x, field.y);
                switch (result)
                {
                //0,1 - incorrect move, no action neccessary, so no case
                case 2:        //remove captured pawn and end turn
                    move_list.Enqueue(field.x);
                    move_list.Enqueue(field.y);
                    winCheck();
                    if (state.check_promotion(field.x, field.y))
                    {
                        if (state.active_side == 1)
                        {
                            field.Image = Properties.Resources.white_king;
                        }
                        else
                        {
                            field.Image = Properties.Resources.black_king;
                        }
                    }
                    else
                    {
                        field.Image = highlighted.Image;
                    }
                    field.id          = highlighted.id;
                    highlighted.Image = Properties.Resources.field;
                    highlighted.id    = 0;
                    highlighted.FlatAppearance.BorderSize = 0;
                    highlighted.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
                    phase = 0;
                    ((DraughtsButton)this.Controls.Find(state.to_kill, false)[0]).Image = Properties.Resources.field;
                    change_active();
                    break;

                case 3:        //further captures possible
                    move_list.Enqueue(field.x);
                    move_list.Enqueue(field.y);
                    winCheck();
                    if (state.check_promotion(field.x, field.y))
                    {
                        if (state.active_side == 1)
                        {
                            field.Image = Properties.Resources.white_king;
                        }
                        else
                        {
                            field.Image = Properties.Resources.black_king;
                        }
                    }
                    else
                    {
                        field.Image = highlighted.Image;
                    }
                    field.id = highlighted.id;
                    field.FlatAppearance.BorderColor = Color.DarkGreen;
                    field.FlatAppearance.BorderSize  = 2;
                    highlighted.Image = Properties.Resources.field;
                    ((DraughtsButton)this.Controls.Find(state.to_kill, false)[0]).Image = Properties.Resources.field;
                    highlighted.id = 0;
                    highlighted.FlatAppearance.BorderSize = 0;
                    highlighted.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
                    highlighted           = field;
                    phase = 2;
                    break;
                }
                break;
            }
        }