Ejemplo n.º 1
0
        private void button1_Click(object sender, System.EventArgs e)
        {
            BackgroundImage = ((System.Drawing.Image)(Properties.Resources.gamecover1));
            bool auto;
            char turn = 't';
            char previous = 'n', current = 'n';
            int  previous_i = 0, previous_j = 0;
            int  current_i, current_j;
            byte count1, count2;
            bool message = false;

            Button[,] buttons = new Button[8, 8];
            int[,] point2     = new int[3, 2];


            button1.Hide();
            startCombo.Hide();
            choosestart.Hide();



            GameBoard  gameboard = new GameBoard();
            AutoPlayer clinton   = new AutoPlayer();

            Player clintons = new Player();
            Player trumps   = new Player();



            if (startCombo.SelectedIndex == 1)
            {
                auto = false;
            }
            else
            {
                auto = true;
            }


            for (int i = 0; i < 8; i++)
            {
                for (int j = 0; j < 8; j++)
                {
                    Button button = new Button();
                    button.Height   = 50;
                    button.Width    = 50;
                    button.Location = new Point(200 + 50 * i, 50 * j);
                    if ((i + j) % 2 == 1)
                    {
                        button.BackColor = Color.Black;
                        button.FlatStyle = FlatStyle.Flat;
                        button.FlatAppearance.BorderColor = Color.Black;
                        if (j < 3)
                        {
                            button.BackgroundImage = ((System.Drawing.Image)(Properties.Resources.clinton));
                        }
                        else if (j > 4 && j < 8)
                        {
                            button.BackgroundImage = ((System.Drawing.Image)(Properties.Resources.trump1));
                        }
                        else
                        {
                            button.BackgroundImage = null;
                        }
                    }

                    if ((i + j) % 2 == 1)
                    {
                        button.Click += (s, ea) =>
                        {
                            if (auto)
                            {
                                current_i = (button.Location.X - 200) / 50;
                                current_j = button.Location.Y / 50;
                                switch (gameboard[current_i, current_j])
                                {
                                case 2:
                                case 20: current = 't'; break;

                                case 0: current = 'n'; break;
                                }
                                //Trump's step
                                if (turn == 't' && trumps.Step(turn, previous, current, current_i, current_j, previous_i, previous_j) && gameboard[previous_i, previous_j] == 2)
                                {
                                    point2 = trumps.Huff(gameboard, 2, 1);
                                    if (point2[0, 0] == -1 && point2[0, 1] == -1)
                                    {
                                        turn = 'c';
                                        buttons[previous_i, previous_j].BackgroundImage = null;

                                        if (current_j == 0 && gameboard[previous_i, previous_j] == 2)
                                        {
                                            gameboard[previous_i, previous_j] = 0;
                                            gameboard[current_i, current_j]   = 20;
                                            button.BackgroundImage            = ((System.Drawing.Image)(Properties.Resources.damatrump));
                                        }
                                        else
                                        {
                                            gameboard[previous_i, previous_j] = 0;
                                            gameboard[current_i, current_j]   = 2;
                                            button.BackgroundImage            = ((System.Drawing.Image)(Properties.Resources.trump1));
                                        }
                                    }
                                    else
                                    {
                                        int x = point2[0, 0];
                                        int y = point2[0, 1];
                                        turn = 'c';
                                        buttons[x, y].BackgroundImage = null;
                                        gameboard[x, y] = 0;
                                    }
                                    Thread.Sleep(500);
                                    clinton.AutoStep(clinton, point2, ref turn, ref gameboard, ref buttons, out message);
                                }

                                //Trump's eat
                                if (previous == 't' && trumps.Eating(current, current_i, current_j, previous_i, previous_j, gameboard, 1) && gameboard[previous_i, previous_j] == 2)
                                {
                                    turn = 'c';
                                    buttons[previous_i, previous_j].BackgroundImage = null;

                                    if (current_j == 0 && gameboard[previous_i, previous_j] == 2)
                                    {
                                        gameboard[previous_i, previous_j] = 0;
                                        gameboard[current_i, current_j]   = 20;
                                        button.BackgroundImage            = ((System.Drawing.Image)(Properties.Resources.damatrump));
                                    }
                                    else
                                    {
                                        gameboard[previous_i, previous_j] = 0;
                                        gameboard[current_i, current_j]   = 2;
                                        button.BackgroundImage            = ((System.Drawing.Image)(Properties.Resources.trump1));
                                    }
                                    gameboard[(previous_i + current_i) / 2, (previous_j + current_j) / 2] = 0;
                                    buttons[(previous_i + current_i) / 2, (previous_j + current_j) / 2].BackgroundImage = null;


                                    Thread.Sleep(500);
                                    clinton.AutoStep(clinton, point2, ref turn, ref gameboard, ref buttons, out message);
                                }

                                //Trump's dama step
                                if (turn == 't' && previous == 't' && current == 'n' && trumps.Clean(current_i, current_j, previous_i, previous_j, gameboard) && gameboard[previous_i, previous_j] == 20)
                                {
                                    point2 = trumps.Huff(gameboard, 2, 1);
                                    if (point2[0, 0] == -1 && point2[0, 1] == -1)
                                    {
                                        turn = 'c';
                                        buttons[previous_i, previous_j].BackgroundImage = null;
                                        button.BackgroundImage            = ((System.Drawing.Image)(Properties.Resources.damatrump));
                                        gameboard[previous_i, previous_j] = 0;
                                        gameboard[current_i, current_j]   = 20;
                                    }
                                    else
                                    {
                                        int x = point2[0, 0];
                                        int y = point2[0, 1];
                                        turn = 'c';
                                        buttons[x, y].BackgroundImage = null;
                                        gameboard[x, y] = 0;
                                    }
                                    Thread.Sleep(500);
                                    clinton.AutoStep(clinton, point2, ref turn, ref gameboard, ref buttons, out message);
                                }

                                //Trump dama eat
                                if (previous == 't' && current == 'n' && trumps.DamaEat(current_i, current_j, previous_i, previous_j, gameboard, 2, 1) && gameboard[previous_i, previous_j] == 20)
                                {
                                    turn = 'c';
                                    trumps.RemoveCoin(gameboard, ref buttons);
                                    gameboard[previous_i, previous_j] = 0;
                                    gameboard[current_i, current_j]   = 20;
                                    buttons[previous_i, previous_j].BackgroundImage = null;
                                    button.BackgroundImage = ((System.Drawing.Image)(Properties.Resources.damatrump));

                                    Thread.Sleep(500);
                                    clinton.AutoStep(clinton, point2, ref turn, ref gameboard, ref buttons, out message);
                                }



                                previous   = current;
                                previous_i = current_i;
                                previous_j = current_j;


                                Calculations.CoinsCount(gameboard, out count1, out count2);
                                if (count2 == 0)
                                {
                                    RemoveButtons(buttons);
                                    button1.Show();
                                    choosestart.Show();
                                    startCombo.Show();
                                    MessageBox.Show("Congratulations! The winner is Hillary Clinton.");
                                }
                                else
                                if (count1 == 0 || message)
                                {
                                    RemoveButtons(buttons);
                                    button1.Show();
                                    choosestart.Show();
                                    startCombo.Show();
                                    MessageBox.Show("Congratulations! The winner is Donald Trump.");
                                }
                            }
                            else
                            {
                                current_i = (button.Location.X - 200) / 50;
                                current_j = button.Location.Y / 50;

                                switch (gameboard[current_i, current_j])
                                {
                                case 2:
                                case 20: current = 't'; break;

                                case 1:
                                case 10: current = 'c'; break;

                                case 0: current = 'n'; break;
                                }

                                //Trump's step
                                if (turn == 't' && trumps.Step(turn, previous, current, current_i, current_j, previous_i, previous_j) && gameboard[previous_i, previous_j] == 2)
                                {
                                    point2 = trumps.Huff(gameboard, 2, 1);
                                    if (point2[0, 0] == -1 && point2[0, 1] == -1)
                                    {
                                        turn = 'c';
                                        buttons[previous_i, previous_j].BackgroundImage = null;

                                        if (current_j == 0 && gameboard[previous_i, previous_j] == 2)
                                        {
                                            gameboard[previous_i, previous_j] = 0;
                                            gameboard[current_i, current_j]   = 20;
                                            button.BackgroundImage            = ((System.Drawing.Image)(Properties.Resources.damatrump));
                                        }
                                        else
                                        {
                                            gameboard[previous_i, previous_j] = 0;
                                            gameboard[current_i, current_j]   = 2;
                                            button.BackgroundImage            = ((System.Drawing.Image)(Properties.Resources.trump1));
                                        }
                                    }
                                    else
                                    {
                                        int x = point2[0, 0];
                                        int y = point2[0, 1];
                                        turn = 'c';
                                        buttons[x, y].BackgroundImage = null;
                                        gameboard[x, y] = 0;
                                    }
                                }

                                //Trump's eat
                                if (previous == 't' && trumps.Eating(current, current_i, current_j, previous_i, previous_j, gameboard, 1) && gameboard[previous_i, previous_j] == 2)
                                {
                                    turn = 'c';
                                    buttons[previous_i, previous_j].BackgroundImage = null;

                                    if (current_j == 0 && gameboard[previous_i, previous_j] == 2)
                                    {
                                        gameboard[previous_i, previous_j] = 0;
                                        gameboard[current_i, current_j]   = 20;
                                        button.BackgroundImage            = ((System.Drawing.Image)(Properties.Resources.damatrump));
                                    }
                                    else
                                    {
                                        gameboard[previous_i, previous_j] = 0;
                                        gameboard[current_i, current_j]   = 2;
                                        button.BackgroundImage            = ((System.Drawing.Image)(Properties.Resources.trump1));
                                    }
                                    gameboard[(previous_i + current_i) / 2, (previous_j + current_j) / 2] = 0;
                                    buttons[(previous_i + current_i) / 2, (previous_j + current_j) / 2].BackgroundImage = null;
                                }

                                //Trump's dama step
                                if (turn == 't' && previous == 't' && current == 'n' && trumps.Clean(current_i, current_j, previous_i, previous_j, gameboard) && gameboard[previous_i, previous_j] == 20)
                                {
                                    point2 = trumps.Huff(gameboard, 2, 1);
                                    if (point2[0, 0] == -1 && point2[0, 1] == -1)
                                    {
                                        turn = 'c';
                                        buttons[previous_i, previous_j].BackgroundImage = null;
                                        button.BackgroundImage            = ((System.Drawing.Image)(Properties.Resources.damatrump));
                                        gameboard[previous_i, previous_j] = 0;
                                        gameboard[current_i, current_j]   = 20;
                                    }
                                    else
                                    {
                                        int x = point2[0, 0];
                                        int y = point2[0, 1];
                                        turn = 'c';
                                        buttons[x, y].BackgroundImage = null;
                                        gameboard[x, y] = 0;
                                    }
                                }

                                //Trump dama eat
                                if (previous == 't' && current == 'n' && trumps.DamaEat(current_i, current_j, previous_i, previous_j, gameboard, 2, 1) && gameboard[previous_i, previous_j] == 20)
                                {
                                    turn = 'c';
                                    trumps.RemoveCoin(gameboard, ref buttons);
                                    gameboard[previous_i, previous_j] = 0;
                                    gameboard[current_i, current_j]   = 20;
                                    buttons[previous_i, previous_j].BackgroundImage = null;
                                    button.BackgroundImage = ((System.Drawing.Image)(Properties.Resources.damatrump));
                                }

                                //Clinton's step
                                if (turn == 'c' && clintons.Step(turn, previous, current, current_i, current_j, previous_i, previous_j) && gameboard[previous_i, previous_j] == 1)
                                {
                                    point2 = clintons.Huff(gameboard, 1, 2);
                                    if (point2[0, 0] == -1 && point2[0, 1] == -1)
                                    {
                                        turn = 't';
                                        buttons[previous_i, previous_j].BackgroundImage = null;

                                        if (current_j == 7 && gameboard[previous_i, previous_j] == 1)
                                        {
                                            gameboard[previous_i, previous_j] = 0;
                                            gameboard[current_i, current_j]   = 10;
                                            button.BackgroundImage            = ((System.Drawing.Image)(Properties.Resources.damaclinton));
                                        }
                                        else
                                        {
                                            gameboard[previous_i, previous_j] = 0;
                                            gameboard[current_i, current_j]   = 1;
                                            button.BackgroundImage            = ((System.Drawing.Image)(Properties.Resources.clinton));
                                        }
                                    }
                                    else
                                    {
                                        int x = point2[0, 0];
                                        int y = point2[0, 1];
                                        turn = 't';
                                        buttons[x, y].BackgroundImage = null;
                                        gameboard[x, y] = 0;
                                    }
                                }

                                //Clintons's eat
                                if (previous == 'c' && clintons.Eating(current, current_i, current_j, previous_i, previous_j, gameboard, 2) && gameboard[previous_i, previous_j] == 1)
                                {
                                    turn = 't';
                                    buttons[previous_i, previous_j].BackgroundImage = null;

                                    if (current_j == 7 && gameboard[previous_i, previous_j] == 1)
                                    {
                                        gameboard[previous_i, previous_j] = 0;
                                        gameboard[current_i, current_j]   = 10;
                                        button.BackgroundImage            = ((System.Drawing.Image)(Properties.Resources.damaclinton));
                                    }
                                    else
                                    {
                                        gameboard[previous_i, previous_j] = 0;
                                        gameboard[current_i, current_j]   = 1;
                                        button.BackgroundImage            = ((System.Drawing.Image)(Properties.Resources.clinton));
                                    }
                                    gameboard[(previous_i + current_i) / 2, (previous_j + current_j) / 2] = 0;
                                    buttons[(previous_i + current_i) / 2, (previous_j + current_j) / 2].BackgroundImage = null;
                                }

                                //Clinton Dama step
                                if (turn == 'c' && previous == 'c' && current == 'n' && clintons.Clean(current_i, current_j, previous_i, previous_j, gameboard) && gameboard[previous_i, previous_j] == 10)
                                {
                                    point2 = clintons.Huff(gameboard, 1, 2);
                                    if (point2[0, 0] == -1 && point2[0, 1] == -1)
                                    {
                                        turn = 't';
                                        buttons[previous_i, previous_j].BackgroundImage = null;
                                        gameboard[previous_i, previous_j] = 0;
                                        gameboard[current_i, current_j]   = 10;
                                        button.BackgroundImage            = ((System.Drawing.Image)(Properties.Resources.damaclinton));
                                    }
                                    else
                                    {
                                        int x = point2[0, 0];
                                        int y = point2[0, 1];
                                        turn = 't';
                                        buttons[x, y].BackgroundImage = null;
                                        gameboard[x, y] = 0;
                                    }
                                }

                                //Clinton Dama eat
                                if (previous == 'c' && current == 'n' && clintons.DamaEat(current_i, current_j, previous_i, previous_j, gameboard, 1, 2) && gameboard[previous_i, previous_j] == 10)
                                {
                                    turn = 't';
                                    clintons.RemoveCoin(gameboard, ref buttons);
                                    gameboard[previous_i, previous_j] = 0;
                                    gameboard[current_i, current_j]   = 10;
                                    buttons[previous_i, previous_j].BackgroundImage = null;
                                    button.BackgroundImage = ((System.Drawing.Image)(Properties.Resources.damaclinton));
                                }


                                previous   = current;
                                previous_i = current_i;
                                previous_j = current_j;
                                Calculations.CoinsCount(gameboard, out count1, out count2);
                                if (count2 == 0)
                                {
                                    RemoveButtons(buttons);
                                    button1.Show();
                                    choosestart.Show();
                                    startCombo.Show();
                                    MessageBox.Show("Congratulations! The winner is Hillary Clinton.");
                                }
                                else
                                if (count1 == 0)
                                {
                                    RemoveButtons(buttons);
                                    button1.Show();
                                    choosestart.Show();
                                    startCombo.Show();
                                    MessageBox.Show("Congratulations! The winner is Donald Trump.");
                                }
                            }
                        };
                        button.MouseDown += (s, ea) => { button.FlatAppearance.BorderColor = Color.Silver; };
                        button.MouseUp   += (s, ea) => { button.FlatAppearance.BorderColor = Color.Black; };
                    }
                    buttons[i, j] = button;
                    this.Controls.Add(button);
                }
            }
        }
Ejemplo n.º 2
0
 public GameBoard GetCurrentBoard()
 {
     GameBoard board = new GameBoard();
     for (int row = 1; row < 9; row++)
     {
         for (int column = 0; column < 8; column++)
         {
             StackPanel stackPanel = (StackPanel)GetGridElement(CheckersGrid, row, column);
             if (stackPanel.Children.Count > 0)
             {
                 Button button = (Button)stackPanel.Children[0];
                 if (button.Name.Contains("Red"))
                 {
                     if (button.Name.Contains("King"))
                         board.SetGameBoardState(row - 1, column, 3);
                     else
                         board.SetGameBoardState(row - 1, column, 1);
                 }
                 else if (button.Name.Contains("Black"))
                 {
                     if (button.Name.Contains("King"))
                         board.SetGameBoardState(row - 1, column, 4);
                     else
                         board.SetGameBoardState(row - 1, column, 2);
                 }
                 else
                     board.SetGameBoardState(row - 1, column, 0);
             }
             else
             {
                 board.SetGameBoardState(row - 1, column, -1);
             }
         }
     }
     return board;
 }
Ejemplo n.º 3
0
 public virtual int[,] Huff(GameBoard board, byte a, byte b)
 {
     int[,] point = { { -1, -1 }, { -1, -1 }, { -1, -1 } };
     for (int i = 0; i < 6; i++)
     {
         for (int j = 0; j < 6; j++)
         {
             if (board[i, j] == a && (board[i + 1, j + 1] == b || board[i + 1, j + 1] == b * 10) && board[i + 2, j + 2] == 0)
             {
                 point[0, 0] = i;
                 point[0, 1] = j;
                 point[1, 0] = i + 1;
                 point[1, 1] = j + 1;
                 point[2, 0] = i + 2;
                 point[2, 1] = j + 2;
                 return(point);
             }
             if (board[i, j] == a * 10)
             {
                 m = i + 1;
                 n = j + 1;
                 while (board[m, n] == 0 && m < 7 && n < 7)
                 {
                     m++;
                     n++;
                 }
                 if ((board[m, n] == b || board[m, n] == b * 10) && board[m + 1, n + 1] == 0)
                 {
                     point[0, 0] = i;
                     point[0, 1] = j;
                     point[1, 0] = m;
                     point[1, 1] = n;
                     point[2, 0] = m + 1;
                     point[2, 1] = n + 1;
                     return(point);
                 }
             }
         }
     }
     for (int i = 2; i < 8; i++)
     {
         for (int j = 2; j < 8; j++)
         {
             if (board[i, j] == a && (board[i - 1, j - 1] == b || board[i - 1, j - 1] == b * 10) && board[i - 2, j - 2] == 0)
             {
                 point[0, 0] = i;
                 point[0, 1] = j;
                 point[1, 0] = i - 1;
                 point[1, 1] = j - 1;
                 point[2, 0] = i - 2;
                 point[2, 1] = j - 2;
                 return(point);
             }
             if (board[i, j] == a * 10)
             {
                 m = i - 1;
                 n = j - 1;
                 while (board[m, n] == 0 && m > 0 && n > 0)
                 {
                     m--;
                     n--;
                 }
                 if ((board[m, n] == b || board[m, n] == b * 10) && board[m - 1, n - 1] == 0)
                 {
                     point[0, 0] = i;
                     point[0, 1] = j;
                     point[1, 0] = m;
                     point[1, 1] = n;
                     point[2, 0] = m - 1;
                     point[2, 1] = n - 1;
                     return(point);
                 }
             }
         }
     }
     for (int i = 0; i < 6; i++)
     {
         for (int j = 2; j < 8; j++)
         {
             if (board[i, j] == a && (board[i + 1, j - 1] == b || board[i + 1, j - 1] == b * 10) && board[i + 2, j - 2] == 0)
             {
                 point[0, 0] = i;
                 point[0, 1] = j;
                 point[1, 0] = i + 1;
                 point[1, 1] = j - 1;
                 point[2, 0] = i + 2;
                 point[2, 1] = j - 2;
                 return(point);
             }
             if (board[i, j] == a * 10)
             {
                 m = i + 1;
                 n = j - 1;
                 while (board[m, n] == 0 && m < 7 && n > 0)
                 {
                     m++;
                     n--;
                 }
                 if ((board[m, n] == b || board[m, n] == b * 10) && board[m + 1, n - 1] == 0)
                 {
                     point[0, 0] = i;
                     point[0, 1] = j;
                     point[1, 0] = m;
                     point[1, 1] = n;
                     point[2, 0] = m + 1;
                     point[2, 1] = n - 1;
                     return(point);
                 }
             }
         }
     }
     for (int i = 2; i < 8; i++)
     {
         for (int j = 0; j < 6; j++)
         {
             if (board[i, j] == a && (board[i - 1, j + 1] == b || board[i - 1, j + 1] == b * 10) && board[i - 2, j + 2] == 0)
             {
                 point[0, 0] = i;
                 point[0, 1] = j;
                 point[1, 0] = i - 1;
                 point[1, 1] = j + 1;
                 point[2, 0] = i - 2;
                 point[2, 1] = j + 2;
                 return(point);
             }
             if (board[i, j] == a * 10)
             {
                 m = i - 1;
                 n = j + 1;
                 while (board[m, n] == 0 && m > 0 && n < 7)
                 {
                     m--;
                     n++;
                 }
                 if ((board[m, n] == b || board[m, n] == b * 10) && board[m - 1, n + 1] == 0)
                 {
                     point[0, 0] = i;
                     point[0, 1] = j;
                     point[1, 0] = m;
                     point[1, 1] = n;
                     point[2, 0] = m - 1;
                     point[2, 1] = n + 1;
                     return(point);
                 }
             }
         }
     }
     return(point);
 }
Ejemplo n.º 4
0
 internal void PrintBoard()
 {
     Console.WriteLine(GameBoard.ToString());
 }
Ejemplo n.º 5
0
        public virtual bool DamaEat(int curi, int curj, int previ, int prevj, GameBoard board, byte a, byte b)
        {
            byte count1 = 0;
            byte count2 = 0;

            if (curi < previ && curj < prevj)
            {
                j    = curj;
                mini = curi;
                maxi = previ;
            }
            else if (curi > previ && curj > prevj)
            {
                j    = prevj;
                mini = previ;
                maxi = curi;
            }
            else if (curi > previ && curj < prevj)
            {
                j    = prevj;
                mini = previ;
                maxi = curi;
                //bug prevj--
            }
            else if (curi < previ && curj > prevj)
            {
                mini = curi;
                maxi = previ;
                j    = curj;
                //bug prevj--
            }


            for (int i = mini + 1; i < maxi; i++)
            {
                if ((curi < previ && curj < prevj) || (curi > previ && curj > prevj))
                {
                    j++;
                }
                else if ((curi > previ && curj < prevj) || (curi < previ && curj > prevj))
                {
                    j--;
                }
                if (board[i, j] == a)
                {
                    count1++;
                    removedi = i;
                    removedj = j;
                }
                if (board[i, j] == b)
                {
                    count2++;
                }
            }
            if (count1 == 0 && count2 == 1)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 6
0
 public virtual void RemoveCoin(GameBoard board, ref Button[,] buttons)
 {
     buttons[removedi, removedj].BackgroundImage = null;
     board[removedi, removedj] = 0;
 }
Ejemplo n.º 7
0
 public override void RemoveCoin(GameBoard board, ref Button[,] buttons)
 {
     base.RemoveCoin(board, ref buttons);
 }
Ejemplo n.º 8
0
 public virtual bool  Eating(char cur, int curi, int curj, int previ, int prevj, GameBoard board, byte a)
 {
     if ((cur == 'n' &&
          ((curi == previ - 2 && curj == prevj + 2 && (board[previ - 1, prevj + 1] == a || board[previ - 1, prevj + 1] == a * 10)) ||
           (curi == previ - 2 && curj == prevj - 2 && (board[previ - 1, prevj - 1] == a || board[previ - 1, prevj - 1] == a * 10)) ||
           (curi == previ + 2 && curj == prevj + 2 && (board[previ + 1, prevj + 1] == a || board[previ + 1, prevj + 1] == a * 10)) ||
           (curi == previ + 2 && curj == prevj - 2 && (board[previ + 1, prevj - 1] == a || board[previ + 1, prevj - 1] == a * 10)))))
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Ejemplo n.º 9
0
 public override int[,] Huff(GameBoard board, byte a, byte b)
 {
     return(base.Huff(board, a, b));
 }
Ejemplo n.º 10
0
 public override bool Eating(char cur, int curi, int curj, int previ, int prevj, GameBoard board, byte a)
 {
     return(base.Eating(cur, curi, curj, previ, prevj, board, a));
 }
Ejemplo n.º 11
0
 public override bool DamaEat(int curi, int curj, int previ, int prevj, GameBoard board, byte a, byte b)
 {
     return(base.DamaEat(curi, curj, previ, prevj, board, a, b));
 }
Ejemplo n.º 12
0
 public override bool Clean(int curi, int curj, int previ, int prevj, GameBoard board)
 {
     return(base.Clean(curi, curj, previ, prevj, board));
 }
Ejemplo n.º 13
0
        public int[,] Step(GameBoard board)
        {
            List <MyCoin> mycoins = new List <MyCoin>();

            newboard = board;
            for (int j = 0; j < 7; j++)
            {
                for (int i = 0; i <= 7; i++)
                {
                    if (newboard[i, j] == 1)
                    {
                        MyCoin mycoin = new MyCoin();
                        mycoin.x         = i;
                        mycoin.y         = j;
                        mycoin.leftrisk  = 0;
                        mycoin.rightrisk = 0;
                        if (i == 0)
                        {
                            mycoin.leftrisk = null;
                            ii = i + 1;
                            jj = j + 1;
                            if (board[ii, jj] != 0)
                            {
                                mycoin.rightrisk = null;
                            }
                            else if (jj != 7)
                            {
                                newboard[i, j]   = 0;
                                newboard[ii, jj] = 1;
                                if (newboard[ii + 1, jj + 1] == 2 && newboard[ii - 1, jj - 1] == 0)
                                {
                                    mycoin.rightrisk++;
                                }
                                if (newboard[ii - 1, jj + 1] == 2 && newboard[ii + 1, jj - 1] == 0)
                                {
                                    mycoin.rightrisk++;
                                }
                                if (newboard[ii + 1, jj - 1] == 2 && newboard[ii - 1, jj + 1] == 0)
                                {
                                    mycoin.rightrisk++;
                                }
                                newboard[i, j]   = 1;
                                newboard[ii, jj] = 0;
                            }
                            if (jj == 7)
                            {
                                mycoin.rightrisk = -1;
                            }
                        }
                        else if (i == 7)
                        {
                            mycoin.rightrisk = null;

                            ii = i - 1;
                            jj = j + 1;
                            if (board[ii, jj] != 0)
                            {
                                mycoin.leftrisk = null;
                            }
                            else if (jj != 7)
                            {
                                newboard[i, j]   = 0;
                                newboard[ii, jj] = 1;
                                if (newboard[ii + 1, jj + 1] == 2 && newboard[ii - 1, jj - 1] == 0)
                                {
                                    mycoin.leftrisk++;
                                }
                                if (newboard[ii - 1, jj - 1] == 2 && newboard[ii + 1, jj + 1] == 0)
                                {
                                    mycoin.leftrisk++;
                                }
                                if (newboard[ii - 1, jj + 1] == 2 && newboard[ii + 1, jj - 1] == 0)
                                {
                                    mycoin.leftrisk++;
                                }
                                newboard[i, j]   = 1;
                                newboard[ii, jj] = 0;
                            }
                            if (jj == 7)
                            {
                                mycoin.leftrisk = -1;
                            }
                        }
                        else
                        {
                            //left

                            ii = i - 1;
                            jj = j + 1;
                            if (board[ii, jj] != 0)
                            {
                                mycoin.leftrisk = null;
                            }
                            else
                            if (ii != 0 && jj != 7)
                            {
                                newboard[i, j]   = 0;
                                newboard[ii, jj] = 1;
                                if (newboard[ii + 1, jj + 1] == 2 && newboard[ii - 1, jj - 1] == 0)
                                {
                                    mycoin.leftrisk++;
                                }
                                if (newboard[ii + 1, jj - 1] == 2 && newboard[ii - 1, jj + 1] == 0)
                                {
                                    mycoin.leftrisk++;
                                }
                                if (newboard[ii - 1, jj - 1] == 2 && newboard[ii + 1, jj + 1] == 0)
                                {
                                    mycoin.leftrisk++;
                                }
                                if (newboard[ii - 1, jj + 1] == 2 && newboard[ii + 1, jj - 1] == 0)
                                {
                                    mycoin.leftrisk++;
                                }
                                newboard[i, j]   = 1;
                                newboard[ii, jj] = 0;
                            }
                            if (jj == 7)
                            {
                                mycoin.leftrisk = -1;
                            }


                            //right

                            ii = i + 1;
                            jj = j + 1;
                            if (board[ii, jj] != 0)
                            {
                                mycoin.rightrisk = null;
                            }
                            else
                            if (ii != 7 && jj != 7)
                            {
                                newboard[i, j]   = 0;
                                newboard[ii, jj] = 1;
                                if (newboard[ii - 1, jj - 1] == 2 && newboard[ii + 1, jj + 1] == 0)
                                {
                                    mycoin.rightrisk++;
                                }
                                if (newboard[ii - 1, jj + 1] == 2 && newboard[ii + 1, jj - 1] == 0)
                                {
                                    mycoin.rightrisk++;
                                }
                                if (newboard[ii + 1, jj + 1] == 2 && newboard[ii - 1, jj - 1] == 0)
                                {
                                    mycoin.rightrisk++;
                                }
                                if (newboard[ii + 1, jj - 1] == 2 && newboard[ii - 1, jj + 1] == 0)
                                {
                                    mycoin.rightrisk++;
                                }
                                newboard[i, j]   = 1;
                                newboard[ii, jj] = 0;
                            }
                            if (jj == 7)
                            {
                                mycoin.rightrisk = -1;
                            }
                        }

                        mycoins.Add(mycoin);
                    }
                }
            }

            List <int?> right = MyCoin.RightSort(mycoins);
            List <int?> left  = MyCoin.LeftSort(mycoins);

            if (right.Count != 0 && left.Count != 0)
            {
                MyCoin rcoin = MyCoin.FindByRightRisk(right[0], mycoins);
                MyCoin lcoin = MyCoin.FindByLeftRisk(left[0], mycoins);
                if (right[0] <= left[0])
                {
                    point[0, 0] = rcoin.x;
                    point[0, 1] = rcoin.y;
                    point[1, 0] = rcoin.x + 1;
                    point[1, 1] = rcoin.y + 1;
                }
                else
                {
                    point[0, 0] = lcoin.x;
                    point[0, 1] = lcoin.y;
                    point[1, 0] = lcoin.x - 1;
                    point[1, 1] = lcoin.y + 1;
                }
            }
            else
            {
                if (right.Count == 0 && left.Count != 0)
                {
                    MyCoin lcoin = MyCoin.FindByLeftRisk(left[0], mycoins);
                    point[0, 0] = lcoin.x;
                    point[0, 1] = lcoin.y;
                    point[1, 0] = lcoin.x - 1;
                    point[1, 1] = lcoin.y + 1;
                }
                else
                if (right.Count != 0 && left.Count == 0)
                {
                    MyCoin rcoin = MyCoin.FindByRightRisk(right[0], mycoins);
                    point[0, 0] = rcoin.x;
                    point[0, 1] = rcoin.y;
                    point[1, 0] = rcoin.x + 1;
                    point[1, 1] = rcoin.y + 1;
                }
                else if (right.Count == 0 && left.Count == 0)
                {
                    message = true;
                }
            }
            return(point);
        }