Example #1
0
 // 行動の反映
 private void ActionDic(Dicision dodic)
 {
     global.log[global.Turn].player = global.currentplayer;
     if (dodic.SI >= 0 && dodic.SI < global.GhostNum)
     {
         if (global.currentplayer == Player.P1)
         {
             if (S1[dodic.SI].flag)
             {
                 if (dodic.AL == Action_Label.Move)
                 {
                     SMove(S1[dodic.SI], dodic.DR);
                 }
                 //else {
                 //  SFire(S1[dodic.SI], dodic.DR);
                 //}
             }
         }
         else
         {
             if (S2[dodic.SI].flag)
             {
                 if (dodic.AL == Action_Label.Move)
                 {
                     SMove(S2[dodic.SI], dodic.DR);
                 }
                 //else {
                 //  SFire(S2[dodic.SI], dodic.DR);
                 //}
             }
         }
     }
 }
Example #2
0
        public override Dicision Dicision()
        {
            Dicision outdic  = new Dicision();
            Random   cRandom = new System.Random();

            while (true)
            {
                int tmp1 = cRandom.Next(0, global.GhostNum);
                if (Function.MyGhostState(tmp1).GetDoA())
                {
                    outdic.SI = tmp1; outdic.AL = Action_Label.Move;
                    while (true)
                    {
                        int tmp = cRandom.Next(0, 4);
                        if (Function.CanDR(Function.MyGhostState(tmp1).GetPos(), (Direction)tmp))
                        {
                            outdic.DR = (Direction)tmp; break;
                        }
                    }
                    break;
                }
            }
            return(outdic);
        }
Example #3
0
        public override Dicision Dicision()
        {
            Dicision outdic  = new Dicision();
            Random   cRandom = new System.Random();
            int      s1;

            while (true)
            {
                var func = new Function();
                int a    = Function.NowTurn();

                if (a < 6)
                {
                    if (a == 1 || a == 2)
                    {
                        outdic.SI = 2; outdic.AL = Action_Label.Move; outdic.DR = Direction.Left;
                    }
                    if (a == 3 || a == 4)
                    {
                        outdic.SI = 4; outdic.AL = Action_Label.Move; outdic.DR = Direction.Right;
                    }
                    if (a == 5 || a == 6)
                    {
                        outdic.SI = 3; outdic.AL = Action_Label.Move; outdic.DR = Direction.Down;
                    }
                    return(outdic);
                }


                if (!Function.MyGhostState(4).GetDoA() && Function.MyGhostState(5).GetDoA())
                {
                    if (Function.CanDR(Function.MyGhostState(5).GetPos(), Direction.Right))
                    {
                        outdic.SI = 5; outdic.AL = Action_Label.Move; outdic.DR = Direction.Right;
                        return(outdic);
                    }
                }
                if (!Function.MyGhostState(5).GetDoA() && Function.MyGhostState(4).GetDoA())
                {
                    if (Function.CanDR(Function.MyGhostState(4).GetPos(), Direction.Up))
                    {
                        outdic.SI = 4; outdic.AL = Action_Label.Move; outdic.DR = Direction.Up;
                        return(outdic);
                    }
                }

                if (a > 170)
                {
                    int total    = 0;
                    var blue_red = Function.GetDeleteEnemyNum();
                    total += blue_red[0] - blue_red[1];
                    for (int i = 0; i < 6; i++)
                    {
                        if (i < 3)
                        {
                            if (Function.MyGhostState(i).GetDoA())
                            {
                                total += 1;
                            }
                        }
                        else
                        {
                            if (Function.MyGhostState(i).GetDoA())
                            {
                                total -= 1;
                            }
                        }
                    }
                    if (total <= 0)
                    {
                        if (Function.MyGhostState(2).GetDoA())
                        {
                            if (Function.CanDR(Function.MyGhostState(2).GetPos(), Direction.Left))
                            {
                                outdic.SI = 2; outdic.AL = Action_Label.Move; outdic.DR = Direction.Left;
                                return(outdic);
                            }
                            else if (Function.CanDR(Function.MyGhostState(2).GetPos(), Direction.Down))
                            {
                                outdic.SI = 2; outdic.AL = Action_Label.Move; outdic.DR = Direction.Down;
                                return(outdic);
                            }
                        }
                        else if (Function.MyGhostState(1).GetDoA())
                        {
                            if (Function.CanDR(Function.MyGhostState(1).GetPos(), Direction.Down))
                            {
                                outdic.SI = 1; outdic.AL = Action_Label.Move; outdic.DR = Direction.Down;
                                return(outdic);
                            }
                            else if (Function.CanDR(Function.MyGhostState(1).GetPos(), Direction.Right))
                            {
                                outdic.SI = 1; outdic.AL = Action_Label.Move; outdic.DR = Direction.Right;
                                return(outdic);
                            }
                        }
                    }
                }


                if (Function.MyGhostState(0).GetDoA() || Function.MyGhostState(3).GetDoA() || Function.MyGhostState(4).GetDoA() || Function.MyGhostState(5).GetDoA())
                {
                    if (Function.MyGhostState(0).GetDoA() || Function.MyGhostState(3).GetDoA())
                    {
                        s1 = 3;
                        if (Function.MyGhostState(s1).GetPos() == new Point(1, 5) || Function.MyGhostState(s1).GetPos() == new Point(1, 4) || Function.MyGhostState(s1).GetPos() == new Point(0, 4) || !Function.MyGhostState(3).GetDoA())
                        {
                            if (Function.MyGhostState(s1).GetPos() == new Point(0, 4))
                            {
                                if (Function.CanDR(Function.MyGhostState(s1).GetPos(), Direction.Right))
                                {
                                    outdic.SI = s1; outdic.AL = Action_Label.Move; outdic.DR = Direction.Right;
                                    return(outdic);
                                }
                            }
                            else if (Function.MyGhostState(s1).GetPos() == new Point(1, 4))
                            {
                                outdic.SI = s1; outdic.AL = Action_Label.Move; outdic.DR = Direction.Down;
                                return(outdic);
                            }
                            s1 = 0;
                        }
                        else
                        {
                            if (Function.CanDR(Function.MyGhostState(s1).GetPos(), Direction.Left))
                            {
                                outdic.SI = s1; outdic.AL = Action_Label.Move; outdic.DR = Direction.Left;
                            }
                            else if (Function.CanDR(Function.MyGhostState(s1).GetPos(), Direction.Down))
                            {
                                outdic.SI = s1; outdic.AL = Action_Label.Move; outdic.DR = Direction.Down;
                            }
                            return(outdic);
                        }
                    }
                    else
                    {
                        s1 = 5;
                    }
                    if (Function.MyGhostState(s1).GetDoA())
                    {
                        if (s1 == 5)
                        {
                            if (Function.MyGhostState(s1).GetPos() != new Point(3, 5))
                            {
                                if (Function.CanDR(Function.MyGhostState(s1).GetPos(), Direction.Down))
                                {
                                    outdic.SI = s1; outdic.AL = Action_Label.Move; outdic.DR = Direction.Down;
                                }
                                else if (Function.CanDR(Function.MyGhostState(s1).GetPos(), Direction.Right))
                                {
                                    outdic.SI = s1; outdic.AL = Action_Label.Move; outdic.DR = Direction.Right;
                                }
                                return(outdic);
                            }
                        }
                        else
                        {
                            if (Function.CanDR(Function.MyGhostState(s1).GetPos(), Direction.Left))
                            {
                                outdic.SI = s1; outdic.AL = Action_Label.Move; outdic.DR = Direction.Left;
                            }
                            else if (Function.CanDR(Function.MyGhostState(s1).GetPos(), Direction.Down))
                            {
                                outdic.SI = s1; outdic.AL = Action_Label.Move; outdic.DR = Direction.Down;
                            }
                            return(outdic);
                        }
                    }

                    return(outdic);
                }
                else
                {
                    int tmp1 = cRandom.Next(0, global.GhostNum);
                    if (Function.MyGhostState(tmp1).GetDoA())
                    {
                        outdic.SI = tmp1; outdic.AL = Action_Label.Move;
                        while (true)
                        {
                            int tmp = cRandom.Next(0, 4);
                            if (Function.CanDR(Function.MyGhostState(tmp1).GetPos(), (Direction)tmp))
                            {
                                outdic.DR = (Direction)tmp; break;
                            }
                        }
                        break;
                    }
                }
            }
            return(outdic);
        }
Example #4
0
        public override Dicision Dicision()
        {
            Dicision outdic  = new Dicision();
            Random   cRandom = new System.Random();

            int maxlevel(int alpha, int beta, int limit, int[,] table_info)
            {
                // 自分の青コマ勝利判定
                if (table_info[0, 5] == 1 || table_info[4, 5] == 1)
                {
                    return(Int32.MaxValue);
                }
                // 敗北判定
                // 自分の青コマカウント
                int my_blue_count = 0;

                for (int i = 0; i < 5; i++)
                {
                    for (int j = 0; j < 6; j++)
                    {
                        if (table_info[i, j] == 1)
                        {
                            my_blue_count = my_blue_count + 1;
                        }
                    }
                }
                if (my_blue_count == 0)
                {
                    return(-Int32.MaxValue + 1);
                }
                if (limit == 0)
                {
                    //評価値
                    //個数の評価値
                    int num_val          = my_blue_count - (3 - Function.GetDeleteEnemyNum()[0]);
                    int my_goal_score    = 0;
                    int enemy_goal_score = 0;
                    for (int i = 0; i < 5; i++)
                    {
                        for (int j = 0; j < 6; j++)
                        {
                            if (table_info[i, j] == 1 || table_info[i, j] == -1)
                            {
                                if (i < 3)
                                {
                                    my_goal_score = my_goal_score + Math.Abs(0 - i) + Math.Abs(5 - j);//マンハッタン距離
                                }
                                else
                                {
                                    my_goal_score = my_goal_score + Math.Abs(4 - i) + Math.Abs(5 - j);//マンハッタン距離
                                }
                            }
                            if (table_info[i, j] == 5)
                            {
                                if (i < 3)
                                {
                                    enemy_goal_score = enemy_goal_score + Math.Abs(0 - i) + Math.Abs(0 - j);//マンハッタン距離
                                }
                                else
                                {
                                    enemy_goal_score = enemy_goal_score + Math.Abs(4 - i) + Math.Abs(0 - j);//マンハッタン距離
                                }
                            }
                        }
                    }
                    //位置の評価値
                    int pos_val = enemy_goal_score - my_goal_score;
                    //評価値
                    int fin_val = num_val + 50 * pos_val;
                    return(fin_val);
                }
                //可能な自分の手をすべて生成
                // Up:0, Right:1, Down:2, Left:3
                List <int[]> pos_hand = new List <int[]>();

                for (int i = 0; i < 5; i++)
                {
                    for (int j = 0; j < 6; j++)
                    {
                        if (table_info[i, j] == 1 || table_info[i, j] == -1)// 自分のコマだったら
                        {
                            //Up可能探索
                            if (j + 1 < 6)
                            {
                                if (j + 1 < 6 && table_info[i, j + 1] != 1 && table_info[i, j + 1] != -1)
                                {
                                    pos_hand.Add(new int[4] {
                                        i, j, 0, 1
                                    });
                                }
                            }
                            //Right可能探索
                            if (i + 1 < 5)
                            {
                                if (i + 1 < 5 && table_info[i + 1, j] != 1 && table_info[i + 1, j] != -1)
                                {
                                    pos_hand.Add(new int[4] {
                                        i, j, 1, 0
                                    });
                                }
                            }
                            //Down可能探索
                            if (j - 1 > -1)
                            {
                                if (j - 1 < 6 && table_info[i, j - 1] != 1 && table_info[i, j - 1] != -1)
                                {
                                    pos_hand.Add(new int[4] {
                                        i, j, 0, -1
                                    });
                                }
                            }
                            //Left可能探索
                            if (i - 1 > -1)
                            {
                                if (i - 1 < 6 && table_info[i - 1, j] != 1 && table_info[i - 1, j] != -1)
                                {
                                    pos_hand.Add(new int[4] {
                                        i, j, -1, 0
                                    });
                                }
                            }
                            // 動かない
                            pos_hand.Add(new int[4] {
                                i, j, 0, 0
                            });
                        }
                    }
                }

                int score_max = -Int32.MaxValue;

                int[,] tmp_table_info = new int[5, 6];
                foreach (int[] tmp_hand in pos_hand)
                {
                    int score;
                    for (int i = 0; i < 5; i++)
                    {
                        for (int j = 0; j < 6; j++)
                        {
                            tmp_table_info[i, j] = table_info[i, j];
                        }
                    }
                    //手を打つ
                    int tmp_ghost_var = tmp_table_info[tmp_hand[0], tmp_hand[1]];
                    tmp_table_info[tmp_hand[0], tmp_hand[1]] = 0;
                    tmp_table_info[tmp_hand[0] + tmp_hand[2], tmp_hand[1] + tmp_hand[3]] = tmp_ghost_var;
                    score = minlevel(alpha, beta, limit - 1, tmp_table_info); //次の相手の手
                                                                              //手を戻す
                                                                              //tmp_ghost_var = table_info[tmp_hand[0]+tmp_hand[2], tmp_hand[1]+tmp_hand[3]];
                                                                              //table_info[tmp_hand[0] + tmp_hand[2], tmp_hand[1] + tmp_hand[3]] = 0;
                                                                              //table_info[tmp_hand[0], tmp_hand[1]] = tmp_ghost_var;
                    if (score >= beta)
                    {
                        // beta 値を上回ったら探索を中止
                        return(score);
                    }

                    if (score > score_max)
                    {
                        score_max = score;
                        if (score_max >= alpha)
                        {
                            alpha = score_max;
                        }
                    }
                }
                return(score_max);
            }

            int minlevel(int alpha, int beta, int limit, int[,] table_info)
            {
                // 敵の青コマ勝利判定
                if (table_info[0, 0] == 5 || table_info[4, 0] == 5)
                {
                    return(-Int32.MaxValue);
                }
                // 敵の紫or赤コマの取得個数が3個以上なら敗北判定
                // 敵の赤コマカウント
                // まず盤面の紫コマ数える
                int enemy_board_count = 0;

                for (int i = 0; i < 5; i++)
                {
                    for (int j = 0; j < 6; j++)
                    {
                        if (table_info[i, j] == 5)
                        {
                            enemy_board_count = enemy_board_count + 1;
                        }
                    }
                }
                // 元の取った敵の赤コマの数
                int pre_red_count = Function.GetDeleteEnemyNum()[1];
                // 元の盤面の紫コマの数
                int pre_board_count = 6 - Function.GetDeleteEnemyNum()[0] - Function.GetDeleteEnemyNum()[1];
                // 取った敵の赤コマの数
                int enemy_red_count = pre_red_count + pre_board_count - enemy_board_count;

                // 敗北判定
                if (enemy_red_count >= 3)
                {
                    return(-Int32.MaxValue + 1);
                }

                if (limit == 0)
                {
                    //評価値
                    int my_blue_count = 0;
                    for (int i = 0; i < 5; i++)
                    {
                        for (int j = 0; j < 6; j++)
                        {
                            if (table_info[i, j] == 1)
                            {
                                my_blue_count = my_blue_count + 1;
                            }
                        }
                    }
                    //個数の評価値
                    int num_val          = my_blue_count - (3 - Function.GetDeleteEnemyNum()[0]);
                    int my_goal_score    = 0;
                    int enemy_goal_score = 0;
                    for (int i = 0; i < 5; i++)
                    {
                        for (int j = 0; j < 6; j++)
                        {
                            if (table_info[i, j] == 1 || table_info[i, j] == -1)
                            {
                                if (i < 3)
                                {
                                    my_goal_score = my_goal_score + Math.Abs(0 - i) + Math.Abs(5 - j);//マンハッタン距離
                                }
                                else
                                {
                                    my_goal_score = my_goal_score + Math.Abs(4 - i) + Math.Abs(5 - j);//マンハッタン距離
                                }
                            }
                            if (table_info[i, j] == 5)
                            {
                                if (i < 3)
                                {
                                    enemy_goal_score = enemy_goal_score + Math.Abs(0 - i) + Math.Abs(0 - j);//マンハッタン距離
                                }
                                else
                                {
                                    enemy_goal_score = enemy_goal_score + Math.Abs(4 - i) + Math.Abs(0 - j);//マンハッタン距離
                                }
                            }
                        }
                    }
                    //位置の評価値
                    int pos_val = enemy_goal_score - my_goal_score;
                    //評価値
                    int fin_val = num_val + 50 * pos_val;
                    return(fin_val);
                }
                //可能な敵の手をすべて生成
                // Up:0, Right:1, Down:2, Left:3
                List <int[]> pos_hand = new List <int[]>();

                for (int i = 0; i < 5; i++)
                {
                    for (int j = 0; j < 6; j++)
                    {
                        if (table_info[i, j] == 5)// 敵のコマだったら
                        {
                            //Up可能探索
                            if (j + 1 < 6)
                            {
                                if (j + 1 < 6 && table_info[i, j + 1] != 5)
                                {
                                    pos_hand.Add(new int[4] {
                                        i, j, 0, 1
                                    });
                                }
                            }
                            //Right可能探索
                            if (i + 1 < 5)
                            {
                                if (i + 1 < 5 && table_info[i + 1, j] != 5)
                                {
                                    pos_hand.Add(new int[4] {
                                        i, j, 1, 0
                                    });
                                }
                            }
                            //Down可能探索
                            if (j - 1 > -1)
                            {
                                if (j - 1 < 6 && table_info[i, j - 1] != 5)
                                {
                                    pos_hand.Add(new int[4] {
                                        i, j, 0, -1
                                    });
                                }
                            }
                            //Left可能探索
                            if (i - 1 > -1)
                            {
                                if (i - 1 < 6 && table_info[i - 1, j] != 5)
                                {
                                    pos_hand.Add(new int[4] {
                                        i, j, -1, 0
                                    });
                                }
                            }
                            // 動かない
                            //pos_hand.Add(new int[4] { i, j, 0, 0 });
                        }
                    }
                }

                int score_min = Int32.MaxValue;

                int[,] tmp_table_info = new int[5, 6];
                foreach (int[] tmp_hand in pos_hand)
                {
                    int score;
                    for (int i = 0; i < 5; i++)
                    {
                        for (int j = 0; j < 6; j++)
                        {
                            tmp_table_info[i, j] = table_info[i, j];
                        }
                    }
                    //手を打つ
                    int tmp_ghost_var = tmp_table_info[tmp_hand[0], tmp_hand[1]];
                    tmp_table_info[tmp_hand[0], tmp_hand[1]] = 0;
                    tmp_table_info[tmp_hand[0] + tmp_hand[2], tmp_hand[1] + tmp_hand[3]] = tmp_ghost_var;
                    score = maxlevel(alpha, beta, limit - 1, tmp_table_info); //次の自分の手
                                                                              //手を戻す
                                                                              //tmp_ghost_var = table_info[tmp_hand[0] + tmp_hand[2], tmp_hand[1] + tmp_hand[3]];
                                                                              //table_info[tmp_hand[0] + tmp_hand[2], tmp_hand[1] + tmp_hand[3]] = 0;
                                                                              //table_info[tmp_hand[0], tmp_hand[1]] = tmp_ghost_var;
                    if (score <= alpha)
                    {
                        //alpha値を下回った探索を中止
                        return(score);
                    }

                    if (score < score_min)
                    {
                        score_min = score;
                        if (score_min <= beta)
                        {
                            beta = score_min;
                        }
                    }
                }
                return(score_min);
            }

            while (true)
            {
                //Console.Write("enego = {0}", Function.EnemyGhostState()[0]);
                // 盤面のロード
                int[,] table_info = new int[5, 6];
                for (int i = 0; i < 5; i++)
                {
                    for (int j = 0; j < 6; j++)
                    {
                        table_info[i, j] = 0;
                    }
                }
                // 盤面のロード(1が青, -1が赤, 5が敵)
                // 自身
                int tmp_x, tmp_y;
                for (int id = 0; id < 6; id++)
                {
                    if (Function.MyGhostState(id).GetDoA() == true)
                    {
                        tmp_x = Function.MyGhostState(id).GetPos().X;
                        tmp_y = Function.MyGhostState(id).GetPos().Y;
                        if (id < 3)
                        {
                            table_info[tmp_x, tmp_y] = 1;
                        }
                        else
                        {
                            table_info[tmp_x, tmp_y] = -1;
                        }
                    }
                }
                // 敵
                List <Point> tmp_enemy_points = Function.EnemyGhostState();
                foreach (Point tmp_enemy_point in tmp_enemy_points)
                {
                    table_info[tmp_enemy_point.X, tmp_enemy_point.Y] = 5;
                }
                int   alpha = -Int32.MaxValue;
                int   beta  = Int32.MaxValue;
                int   eval;
                int   eval_max = -Int32.MaxValue;
                int[] fin_hand = new int[4] {
                    -5, -5, -5, -5
                };                                             //最終的な打ち手
                //可能な自分の手をすべて生成
                // Up:0, Right:1, Down:2, Left:3
                List <int[]> pos_hand = new List <int[]>();
                for (int i = 0; i < 5; i++)
                {
                    for (int j = 0; j < 6; j++)
                    {
                        if (table_info[i, j] == 1 || table_info[i, j] == -1)// 自分のコマだったら
                        {
                            //Up可能探索
                            if (j + 1 < 6)
                            {
                                if (j + 1 < 6 && table_info[i, j + 1] != 1 && table_info[i, j + 1] != -1)
                                {
                                    pos_hand.Add(new int[4] {
                                        i, j, 0, 1
                                    });
                                }
                            }
                            //Right可能探索
                            if (i + 1 < 5)
                            {
                                if (i + 1 < 5 && table_info[i + 1, j] != 1 && table_info[i + 1, j] != -1)
                                {
                                    pos_hand.Add(new int[4] {
                                        i, j, 1, 0
                                    });
                                }
                            }
                            //Down可能探索
                            if (j - 1 > -1)
                            {
                                if (j - 1 < 6 && table_info[i, j - 1] != 1 && table_info[i, j - 1] != -1)
                                {
                                    pos_hand.Add(new int[4] {
                                        i, j, 0, -1
                                    });
                                }
                            }
                            //Left可能探索
                            if (i - 1 > -1)
                            {
                                if (i - 1 < 6 && table_info[i - 1, j] != 1 && table_info[i - 1, j] != -1)
                                {
                                    pos_hand.Add(new int[4] {
                                        i, j, -1, 0
                                    });
                                }
                            }
                            // 動かない
                            pos_hand.Add(new int[4] {
                                i, j, 0, 0
                            });
                        }
                    }
                }

                int[,] tmp_table_info = new int[5, 6];
                // デバッグ用
                //List<int> eval_list = new List<int>();
                foreach (int[] tmp_hand in pos_hand)
                {
                    for (int i = 0; i < 5; i++)
                    {
                        for (int j = 0; j < 6; j++)
                        {
                            tmp_table_info[i, j] = table_info[i, j];
                        }
                    }
                    //手を打つ
                    int tmp_ghost_var = tmp_table_info[tmp_hand[0], tmp_hand[1]];
                    tmp_table_info[tmp_hand[0], tmp_hand[1]] = 0;
                    tmp_table_info[tmp_hand[0] + tmp_hand[2], tmp_hand[1] + tmp_hand[3]] = tmp_ghost_var;
                    eval = minlevel(alpha, beta, 4, tmp_table_info);//次の相手の手
                    //eval_list.Add(eval);
                    //手を戻す
                    //tmp_ghost_var = table_info[tmp_hand[0] + tmp_hand[2], tmp_hand[1] + tmp_hand[3]];
                    //table_info[tmp_hand[0] + tmp_hand[2], tmp_hand[1] + tmp_hand[3]] = 0;
                    //table_info[tmp_hand[0], tmp_hand[1]] = tmp_ghost_var;
                    if (eval >= eval_max)
                    {
                        eval_max = eval;
                        fin_hand = tmp_hand;
                    }
                }

                /*
                 * if (eval_max == -Int32.MaxValue)
                 * {
                 *  foreach (int[] tmp_hand in pos_hand)
                 *  {
                 *      for (int i = 0; i < 5; i++)
                 *      {
                 *          for (int j = 0; j < 6; j++)
                 *          {
                 *              tmp_table_info[i, j] = table_info[i, j];
                 *          }
                 *      }
                 *      //手を打つ
                 *      int tmp_ghost_var = tmp_table_info[tmp_hand[0], tmp_hand[1]];
                 *      tmp_table_info[tmp_hand[0], tmp_hand[1]] = 0;
                 *      tmp_table_info[tmp_hand[0] + tmp_hand[2], tmp_hand[1] + tmp_hand[3]] = tmp_ghost_var;
                 *      eval = minlevel(alpha, beta, 3, tmp_table_info);//次の相手の手
                 *      //eval_list.Add(eval);
                 *      //手を戻す
                 *      tmp_ghost_var = table_info[tmp_hand[0] + tmp_hand[2], tmp_hand[1] + tmp_hand[3]];
                 *      table_info[tmp_hand[0] + tmp_hand[2], tmp_hand[1] + tmp_hand[3]] = 0;
                 *      table_info[tmp_hand[0], tmp_hand[1]] = tmp_ghost_var;
                 *      if (eval >= eval_max)
                 *      {
                 *          eval_max = eval;
                 *          fin_hand = tmp_hand;
                 *      }
                 *  }
                 * }*/

                Point fin_point = new Point(fin_hand[0], fin_hand[1]);
                for (int id = 0; id < 6; id++)
                {
                    if (Function.MyGhostState(id).GetDoA() == true && Function.MyGhostState(id).GetPos() == fin_point)
                    {
                        outdic.SI = id;
                        outdic.AL = Action_Label.Move;
                        if (fin_hand[3] == 1)
                        {
                            outdic.DR = Direction.Down;
                        }
                        else if (fin_hand[2] == 1)
                        {
                            outdic.DR = Direction.Right;
                        }
                        else if (fin_hand[3] == -1)
                        {
                            outdic.DR = Direction.Up;
                        }
                        else if (fin_hand[2] == -1)
                        {
                            outdic.DR = Direction.Left;
                        }
                        if (fin_hand[2] == 0 && fin_hand[3] == 0)
                        {
                            outdic.AL = Action_Label.Dummy; // 動かない
                        }
                        break;
                    }
                }
                break;
            }
            //outdic.SI = 0;
            //outdic.AL = Action_Label.Move;
            //outdic.DR = Direction.Left;
            return(outdic);
        }
Example #5
0
        private void Test_Tick(object sender, EventArgs e)
        {
            Dicision dodic = new Dicision();

            if (stopflag == 0)
            {
                var thread = new Thread(new ThreadStart(() => {
                    if (global.currentplayer == Player.P1)
                    {
                        dodic = P1.Dicision();
                    }
                    else
                    {
                        dodic = P2.Dicision();
                    }
                    ActionDic(dodic);
                }));
                thread.Start();
                Thread.Sleep(250);
                if (thread.IsAlive)
                {
                    thread.Abort();
                }
                //for (1~3)
                //P1[i].pos_y=5 && x= 0or4


                //ghostnum 0~3 青(善)
                //        4~6 赤(悪)
                //Search();
                //生存1 死亡0 脱出状態2
                //青の生存
                if (!S1[0].flag && !S1[1].flag && !S1[2].flag)
                {
                    winflag = 2;
                    pattern = 1;
                }
                if (!S2[0].flag && !S2[1].flag && !S2[2].flag)
                {
                    winflag = 1;
                    pattern = 2;
                }

                if (!S1[3].flag && !S1[4].flag && !S1[5].flag)
                {
                    winflag = 1;
                    pattern = 3;
                }
                if (!S2[3].flag && !S2[4].flag && !S2[5].flag)
                {
                    winflag = 2;
                    pattern = 4;
                }
                for (int i = 0; i < 3; i++)
                {
                    if (global.currentplayer == Player.P1)
                    {
                        if (S1[i].flag)
                        {
                            if (((S1[i].pos.X == 0) || (S1[i].pos.X == 4)) && (S1[i].pos.Y == 5))
                            {
                                if (global.Eflag_p1[i] == 1)
                                {
                                    winflag = 1;
                                    pattern = 5;
                                }
                                else
                                {
                                    global.Eflag_p1[i] = 1;
                                }
                            }
                            else
                            {
                                global.Eflag_p1[i] = -1;
                            }
                        }
                    }
                    else
                    {
                        if (S2[i].flag)
                        {
                            if (((YourPos_X(Player.P2, S2[i].pos.X) == 0) || (YourPos_X(Player.P2, S2[i].pos.X) == 4)) && (YourPos_Y(Player.P2, S2[i].pos.Y) == 0))
                            {
                                if (global.Eflag_p2[i] == 1)
                                {
                                    winflag = 2;
                                    pattern = 6;
                                }
                                else
                                {
                                    global.Eflag_p2[i] = 1;
                                }
                            }
                            else
                            {
                                global.Eflag_p2[i] = -1;
                            }
                        }
                    }
                }

                global.Turn++;
                if (global.Turn >= global.FinalTurn)
                {
                    winflag = 0;
                    double[] keisuu = new double[6] {
                        1, 1, 1, -1, -1, -1
                    };
                    double score1 = 0, score2 = 0, scoreP1 = 0, scoreP2 = 0;
                    for (int i = 0; i < global.GhostNum; i++)
                    {
                        if (S1[i].flag)
                        {
                            score1 += keisuu[i]; scoreP1 += Score_Pos1(S1[i].pos);
                        }
                        if (S2[i].flag)
                        {
                            score2 += keisuu[i]; scoreP2 += Score_Pos1(S2[i].pos);
                        }
                    }
                    if (score1 > score2)
                    {
                        winflag += 1;
                    }
                    else if (score1 < score2)
                    {
                        winflag += 2;
                    }
                    else
                    {
                        if (scoreP1 >= scoreP2)
                        {
                            winflag += 1;
                        }
                        if (scoreP1 <= scoreP2)
                        {
                            winflag += 2;
                        }
                    }
                    stopflag = 1;
                }
                global.currentplayer = (Player)(1 - global.currentplayer);
                if (winflag >= 1)
                {
                    stopflag = 1;
                    if (global.Turn < global.FinalTurn)
                    {
                        global.Turn         -= 1;
                        global.currentplayer = (Player)(1 - global.currentplayer);
                    }
                }



                Invalidate();
            }
        }
Example #6
0
        //行動の定義
        public override Dicision Dicision()
        {
            Dicision outdic  = new Dicision();
            Random   cRandom = new System.Random();

            int[] operate_array = new int[6] {
                3, 4, 2, 5, 0, 1
            };

            while (true)
            {
                int flg = 0;

                for (int i = 0; i < 6; i++)
                {
                    if (Function.MyGhostState(operate_array[i]).GetDoA())
                    {
                        if (Function.CanDR(Function.MyGhostState(operate_array[i]).GetPos(), Direction.Down))
                        {
                            outdic.SI = operate_array[i];
                            outdic.AL = Action_Label.Move;
                            outdic.DR = Direction.Down;
                            flg       = 1;
                            break;
                        }

                        switch (operate_array[i])
                        {
                        case 2:
                            if (Function.CanDR(Function.MyGhostState(operate_array[i]).GetPos(), Direction.Right))
                            {
                                outdic.SI = operate_array[i];
                                outdic.AL = Action_Label.Move;
                                outdic.DR = Direction.Right;
                                flg       = 1;
                            }
                            break;

                        case 0:
                            if (Function.CanDR(Function.MyGhostState(operate_array[i]).GetPos(), Direction.Right))
                            {
                                outdic.SI = operate_array[i];
                                outdic.AL = Action_Label.Move;
                                outdic.DR = Direction.Right;
                                flg       = 1;
                            }
                            break;

                        default:
                            if (Function.CanDR(Function.MyGhostState(operate_array[i]).GetPos(), Direction.Left))
                            {
                                outdic.SI = operate_array[i];
                                outdic.AL = Action_Label.Move;
                                outdic.DR = Direction.Left;
                                flg       = 1;
                            }
                            break;
                        }
                        if (flg == 1)
                        {
                            break;
                        }
                    }
                    else
                    {
                        continue;
                    }
                }

                if (flg == 1)
                {
                    break;
                }

                int tmp1 = cRandom.Next(0, global.GhostNum);
                if (Function.MyGhostState(tmp1).GetDoA())
                {
                    outdic.SI = tmp1; outdic.AL = Action_Label.Move;
                    while (true)
                    {
                        int tmp = cRandom.Next(0, 4);
                        if (Function.CanDR(Function.MyGhostState(tmp1).GetPos(), (Direction)tmp))
                        {
                            outdic.DR = (Direction)tmp; break;
                        }
                    }
                    break;
                }
            }
            return(outdic);
        }
Example #7
0
        //行動の定義
        public override Dicision Dicision()
        {
            Dicision outdic = new Dicision();

            //配置変更
            if (first_pos == 0)
            {
                if (Function.MyGhostState(3).GetDoA() && Function.MyGhostState(3).GetPos().X != 0)
                {
                    outdic.SI = 3; outdic.AL = Action_Label.Move; outdic.DR = Direction.Left;
                }
                else if (Function.MyGhostState(5).GetDoA() && Function.MyGhostState(5).GetPos().X != 4)
                {
                    outdic.SI = 5; outdic.AL = Action_Label.Move; outdic.DR = Direction.Right;
                }
                else if (Function.MyGhostState(4).GetDoA() && Function.MyGhostState(4).GetPos().X != 3)
                {
                    outdic.SI = 4; outdic.AL = Action_Label.Move; outdic.DR = Direction.Right;
                }
                else if (Function.MyGhostState(4).GetDoA() && Function.MyGhostState(4).GetPos().Y != 2)
                {
                    outdic.SI = 4; outdic.AL = Action_Label.Move; outdic.DR = Direction.Down;
                }
                else if (Function.MyGhostState(1).GetDoA() && Function.MyGhostState(1).GetPos().Y != 1)
                {
                    outdic.SI = 1; outdic.AL = Action_Label.Move; outdic.DR = Direction.Down;
                }
                else if (Function.MyGhostState(1).GetDoA() && Function.MyGhostState(1).GetPos().X != 3)
                {
                    outdic.SI = 1; outdic.AL = Action_Label.Move; outdic.DR = Direction.Right;
                }
                else
                {
                    first_pos = 1;
                }
                var epos_list = Function.EnemyGhostState();
                for (int i = 0; i < epos_list.Count(); i++)
                {
                    if ((epos_list[i].X == 0) && (epos_list[i].Y == 0))
                    {
                        if (Function.MyGhostState(0).GetDoA() && Function.CanDR(Function.MyGhostState(0).GetPos(), Direction.Left))
                        {
                            outdic.SI = 0; outdic.AL = Action_Label.Move; outdic.DR = Direction.Left;
                        }
                    }
                    if ((epos_list[i].X == 1) && (epos_list[i].Y == 1))
                    {
                        if (Function.MyGhostState(0).GetDoA() && Function.CanDR(Function.MyGhostState(0).GetPos(), Direction.Down))
                        {
                            outdic.SI = 0; outdic.AL = Action_Label.Move; outdic.DR = Direction.Down;
                        }
                    }
                    if ((epos_list[i].X == 0) && (epos_list[i].Y == 2))
                    {
                        if (Function.MyGhostState(0).GetDoA() && Function.CanDR(Function.MyGhostState(0).GetPos(), Direction.Right))
                        {
                            outdic.SI = 0; outdic.AL = Action_Label.Move; outdic.DR = Direction.Right;
                        }
                    }
                    if ((epos_list[i].X == 4) && (epos_list[i].Y == 0))
                    {
                        if (Function.MyGhostState(2).GetDoA() && Function.CanDR(Function.MyGhostState(2).GetPos(), Direction.Right))
                        {
                            outdic.SI = 2; outdic.AL = Action_Label.Move; outdic.DR = Direction.Right;
                        }
                    }
                    if ((epos_list[i].X == 3) && (epos_list[i].Y == 1))
                    {
                        if (Function.MyGhostState(2).GetDoA() && Function.CanDR(Function.MyGhostState(2).GetPos(), Direction.Down))
                        {
                            outdic.SI = 2; outdic.AL = Action_Label.Move; outdic.DR = Direction.Down;
                        }
                    }
                    if ((epos_list[i].X == 0) && (epos_list[i].Y == 2))
                    {
                        if (Function.MyGhostState(2).GetDoA() && Function.CanDR(Function.MyGhostState(2).GetPos(), Direction.Left))
                        {
                            outdic.SI = 2; outdic.AL = Action_Label.Move; outdic.DR = Direction.Left;
                        }
                    }
                }
            }
            else
            {
                var epos_list = Function.EnemyGhostState();

                if (!(Function.MyGhostState(4).GetDoA()) && Function.MyGhostState(1).GetDoA())
                {
                    Point mypos2 = Function.MyGhostState(1).GetPos();
                    if (mypos2.Y == 5)
                    {
                        if (mypos2.X < 4)
                        {
                            if (Function.CanDR(mypos2, Direction.Right))
                            {
                                outdic.SI = 1;
                            }
                            outdic.AL = Action_Label.Move; outdic.DR = Direction.Right;
                        }
                    }
                    else
                    {
                        if (mypos2.X > 2)
                        {
                            if (Function.CanDR(mypos2, Direction.Left))
                            {
                                outdic.SI = 1;
                            }
                            outdic.AL = Action_Label.Move; outdic.DR = Direction.Left;
                        }
                        else if (mypos2.X < 2)
                        {
                            if (Function.CanDR(mypos2, Direction.Right))
                            {
                                outdic.SI = 1;
                            }
                            outdic.AL = Action_Label.Move; outdic.DR = Direction.Right;
                        }
                        else if (mypos2.Y < 5)
                        {
                            if (Function.CanDR(mypos2, Direction.Down))
                            {
                                outdic.SI = 1;
                            }
                            outdic.AL = Action_Label.Move; outdic.DR = Direction.Down;
                        }
                    }
                }

                //前進(3,4,5)
                for (int j = 3; j < 6; j++)
                {
                    if (Function.MyGhostState(j).GetDoA() && Function.CanDR(Function.MyGhostState(j).GetPos(), Direction.Down))
                    {
                        Point mypos = Function.MyGhostState(j).GetPos();

                        int fflag = 0;
                        for (int i = 0; i < epos_list.Count(); i++)
                        {
                            if ((epos_list[i].X == mypos.X) && (epos_list[i].Y == mypos.Y + 1))
                            {
                                fflag = 1;
                            }
                        }
                        if (fflag == 0)
                        {
                            outdic.SI = j; outdic.AL = Action_Label.Move; outdic.DR = Direction.Down;
                        }
                    }
                }

                if ((Function.MyGhostState(5).GetDoA() && Function.MyGhostState(5).GetPos() == new Point(4, 5)) && (Function.MyGhostState(1).GetDoA() && Function.MyGhostState(1).GetPos() == new Point(3, 5)))
                {
                    if (Function.CanDR(Function.MyGhostState(5).GetPos(), Direction.Up))
                    {
                        outdic.SI = 5; outdic.AL = Action_Label.Move; outdic.DR = Direction.Up;
                    }
                }
                if ((Function.MyGhostState(5).GetDoA() && Function.MyGhostState(5).GetPos() == new Point(4, 4)) && (Function.MyGhostState(1).GetDoA() && Function.MyGhostState(1).GetPos() == new Point(3, 5)))
                {
                    if (Function.CanDR(Function.MyGhostState(1).GetPos(), Direction.Right))
                    {
                        outdic.SI = 1; outdic.AL = Action_Label.Move; outdic.DR = Direction.Right;
                    }
                }

                //追従(1,4)
                if (Function.MyGhostState(4).GetDoA() && Function.MyGhostState(1).GetDoA())
                {
                    if (Function.MyGhostState(4).GetPos().Y != Function.MyGhostState(1).GetPos().Y + 1)
                    {
                        if (Function.CanDR(Function.MyGhostState(1).GetPos(), Direction.Down))
                        {
                            outdic.SI = 1; outdic.AL = Action_Label.Move; outdic.DR = Direction.Down;
                        }
                    }
                }

                //protect(0,2)
                if (Function.MyGhostState(2).GetDoA())
                {
                    Point pos = Function.MyGhostState(2).GetPos();
                    if (pos.X < 3)
                    {
                        if (Function.CanDR(pos, Direction.Right))
                        {
                            outdic.SI = 2;
                        }
                        outdic.AL = Action_Label.Move; outdic.DR = Direction.Right;
                    }
                    else if (pos.X > 3)
                    {
                        if (Function.CanDR(pos, Direction.Left))
                        {
                            outdic.SI = 2;
                        }
                        outdic.AL = Action_Label.Move; outdic.DR = Direction.Left;
                    }
                    else if (pos.Y > 0)
                    {
                        if (Function.CanDR(pos, Direction.Up))
                        {
                            outdic.SI = 2;
                        }
                        outdic.AL = Action_Label.Move; outdic.DR = Direction.Up;
                    }
                    else
                    {
                        for (int i = 0; i < epos_list.Count(); i++)
                        {
                            if ((epos_list[i].X == 4) && (epos_list[i].Y == 0))
                            {
                                if (Function.CanDR(pos, Direction.Right))
                                {
                                    outdic.SI = 2;
                                }
                                outdic.AL = Action_Label.Move; outdic.DR = Direction.Right;
                            }
                            else if ((epos_list[i].X == 3) && (epos_list[i].Y == 1))
                            {
                                if (Function.CanDR(pos, Direction.Down))
                                {
                                    outdic.SI = 2;
                                }
                                outdic.AL = Action_Label.Move; outdic.DR = Direction.Down;
                            }
                            else if ((epos_list[i].X == 2) && (epos_list[i].Y == 0))
                            {
                                if (Function.CanDR(pos, Direction.Left))
                                {
                                    outdic.SI = 2;
                                }
                                outdic.AL = Action_Label.Move; outdic.DR = Direction.Left;
                            }
                        }
                    }
                }


                if (Function.MyGhostState(0).GetDoA())
                {
                    Point pos = Function.MyGhostState(0).GetPos();
                    if (pos.X < 1)
                    {
                        if (Function.CanDR(pos, Direction.Right))
                        {
                            outdic.SI = 0;
                        }
                        outdic.AL = Action_Label.Move; outdic.DR = Direction.Right;
                    }
                    else if (pos.X > 1)
                    {
                        if (Function.CanDR(pos, Direction.Left))
                        {
                            outdic.SI = 0;
                        }
                        outdic.AL = Action_Label.Move; outdic.DR = Direction.Left;
                    }
                    else if (pos.Y > 0)
                    {
                        if (Function.CanDR(pos, Direction.Up))
                        {
                            outdic.SI = 0;
                        }
                        outdic.AL = Action_Label.Move; outdic.DR = Direction.Up;
                    }
                    else
                    {
                        for (int i = 0; i < epos_list.Count(); i++)
                        {
                            if ((epos_list[i].X == 0) && (epos_list[i].Y == 0))
                            {
                                if (Function.CanDR(pos, Direction.Left))
                                {
                                    outdic.SI = 0;
                                }
                                outdic.AL = Action_Label.Move; outdic.DR = Direction.Left;
                            }
                            else if ((epos_list[i].X == 1) && (epos_list[i].Y == 1))
                            {
                                if (Function.CanDR(pos, Direction.Down))
                                {
                                    outdic.SI = 0;
                                }
                                outdic.AL = Action_Label.Move; outdic.DR = Direction.Down;
                            }
                            else if ((epos_list[i].X == 2) && (epos_list[i].Y == 0))
                            {
                                if (Function.CanDR(pos, Direction.Right))
                                {
                                    outdic.SI = 0;
                                }
                                outdic.AL = Action_Label.Move; outdic.DR = Direction.Right;
                            }
                        }
                    }
                }
            }
            return(outdic);
        }
Example #8
0
        private Dicision retDic()
        {
            Dicision retD = new Dicision();

            retD.AL = Action_Label.Move;
            List <Point> lp = Function.EnemyGhostState();

            for (int i = 0; i < lp.Count(); i++)
            {
                if (lp[i].Y == 0)
                {
                    if (lp[i].X == 1)
                    {
                        retD.SI = 0;
                        retD.DR = Direction.Right;
                        return(retD);
                    }
                    if (lp[i].X == 3)
                    {
                        retD.SI = 2;
                        retD.DR = Direction.Left;
                        return(retD);
                    }
                }
                else if (lp[i].Y == 1)
                {
                    if (lp[i].X == 0)
                    {
                        retD.SI = 0;
                        retD.DR = Direction.Down;
                        return(retD);
                    }
                    if (lp[i].X == 4)
                    {
                        retD.SI = 2;
                        retD.DR = Direction.Down;
                        return(retD);
                    }
                }
            }
            if (lg[chasel].GetDoA())
            {
                if (lg[chasel].GetPos() == new Point(1, 0))
                {
                    retD.SI = chasel;
                    retD.DR = Direction.Left;
                    return(retD);
                }
                if (lg[chasel].GetPos() == new Point(0, 1))
                {
                    retD.SI = chasel;
                    retD.DR = Direction.Up;
                    return(retD);
                }
            }
            if (lg[chaser].GetDoA())
            {
                if (lg[2].GetPos() == new Point(3, 0))
                {
                    retD.SI = chaser;
                    retD.DR = Direction.Right;
                    return(retD);
                }
                if (lg[chaser].GetPos() == new Point(4, 1))
                {
                    retD.SI = chaser;
                    retD.DR = Direction.Up;
                    return(retD);
                }
            }

            if (lg[4].GetDoA())
            {
                if (!lg[0].GetDoA())
                {
                    retD.SI = 4;
                    retD.DR = Direction.Left;
                    if (lg[4].GetPos() == new Point(1, 0))
                    {
                        chasel = 4;
                    }
                    return(retD);
                }
                if (!lg[2].GetDoA())
                {
                    retD.SI = 4;
                    retD.DR = Direction.Right;
                    if (lg[4].GetPos() == new Point(3, 0))
                    {
                        chaser = 4;
                    }
                    return(retD);
                }
            }

            if (lg[3].GetDoA())
            {
                retD.SI = 3;
                retD.DR = Direction.Down;
                return(retD);
            }
            else if (lg[5].GetDoA())
            {
                retD.SI = 5;
                retD.DR = Direction.Down;
                return(retD);
            }

            retD.SI = 1;
            retD.DR = Direction.Left;
            return(retD);
        }
Example #9
0
        //行動の定義
        public override Dicision Dicision()
        {
            Dicision outdic = new Dicision();

            outdic.AL = Action_Label.Move;
            lg        = new List <GhostState> {
                Function.MyGhostState(0), Function.MyGhostState(1), Function.MyGhostState(2),
                Function.MyGhostState(3), Function.MyGhostState(4), Function.MyGhostState(5)
            };
            nt = Function.NowTurn();
            if (nt < 8)
            {
                if (nt < 2)
                {
                    outdic.SI = 0;
                    outdic.DR = Direction.Left;
                }
                else if (nt < 4)
                {
                    outdic.SI = 2;
                    outdic.DR = Direction.Right;
                }
                else if (nt < 6)
                {
                    if (lg[3].GetDoA() == true)
                    {
                        outdic.SI = 3;
                        outdic.DR = Direction.Down;
                    }
                    else
                    {
                        outdic.SI = 5;
                        outdic.DR = Direction.Down;
                    }
                }
                else
                {
                    outdic = retDic();
                    if (lg[5].GetDoA() && lg[5].GetPos().Y == 1)
                    {
                        outdic.SI = 5;
                        outdic.DR = Direction.Down;
                    }
                }
            }
            else if (nt > 193)
            {
                if (nt < 196)
                {
                    outdic.SI = 1;
                }
                else if (nt < 198)
                {
                    outdic.SI = chasel;
                }
                else
                {
                    outdic.SI = chaser;
                }
                outdic.DR = Direction.Down;
            }
            else
            {
                outdic = retDic();
            }

            return(outdic);
        }
Example #10
0
        //行動の定義
        public override Dicision Dicision()
        {
            Dicision outdic  = new Dicision();
            Random   cRandom = new System.Random();
            int      x       = 2;

            while (true)
            {
                if (Function.MyGhostState(0).GetDoA() || Function.MyGhostState(1).GetDoA() || Function.MyGhostState(4).GetDoA() ||
                    Function.MyGhostState(5).GetDoA() || Function.MyGhostState(3).GetDoA())
                {
                    if (Function.MyGhostState(0).GetDoA() && Function.CanDR(Function.MyGhostState(0).GetPos(), Direction.Left))
                    {
                        outdic.SI = 0; outdic.AL = Action_Label.Move; outdic.DR = Direction.Left;
                    }

                    else if (Function.MyGhostState(1).GetDoA() && Function.CanDR(Function.MyGhostState(1).GetPos(), Direction.Left))
                    {
                        outdic.SI = 1; outdic.AL = Action_Label.Move; outdic.DR = Direction.Left;
                    }
                    else if (Function.MyGhostState(0).GetDoA() && Function.CanDR(Function.MyGhostState(0).GetPos(), Direction.Down) && x % 2 == 0)
                    {
                        outdic.SI = 0; outdic.AL = Action_Label.Move; outdic.DR = Direction.Down;
                        x++;
                        if (!(Function.MyGhostState(1).GetDoA()))
                        {
                            x--;
                        }
                    }

                    else if (Function.MyGhostState(1).GetDoA() && Function.CanDR(Function.MyGhostState(1).GetPos(), Direction.Down) && x % 2 == 1)
                    {
                        outdic.SI = 1; outdic.AL = Action_Label.Move; outdic.DR = Direction.Down;
                        x++;
                        if (!(Function.MyGhostState(0).GetDoA()))
                        {
                            x--;
                        }
                    }

                    else if (Function.MyGhostState(4).GetDoA() && Function.CanDR(Function.MyGhostState(4).GetPos(), Direction.Right))
                    {
                        outdic.SI = 4; outdic.AL = Action_Label.Move; outdic.DR = Direction.Right;
                    }
                    else if (Function.MyGhostState(5).GetDoA() && Function.CanDR(Function.MyGhostState(5).GetPos(), Direction.Right))
                    {
                        outdic.SI = 5; outdic.AL = Action_Label.Move; outdic.DR = Direction.Right;
                    }
                    else if (Function.MyGhostState(3).GetDoA() && Function.CanDR(Function.MyGhostState(3).GetPos(), Direction.Right))
                    {
                        outdic.SI = 3; outdic.AL = Action_Label.Move; outdic.DR = Direction.Right;
                    }



                    return(outdic);
                }



                else
                {
                    int tmp1 = cRandom.Next(0, global.GhostNum);
                    if (Function.MyGhostState(tmp1).GetDoA())
                    {
                        outdic.SI = tmp1; outdic.AL = Action_Label.Move;
                        while (true)
                        {
                            int tmp = cRandom.Next(0, 4);
                            if (Function.CanDR(Function.MyGhostState(tmp1).GetPos(), (Direction)tmp))
                            {
                                outdic.DR = (Direction)tmp; break;
                            }
                        }
                        break;
                    }
                }
            }
            return(outdic);
        }
Example #11
0
        public override Dicision Dicision()
        {
            Dicision outdic  = new Dicision();
            Random   cRandom = new System.Random();
            int      s1;

            while (true)
            {
                if (Function.MyGhostState(0).GetDoA() || Function.MyGhostState(2).GetDoA())
                {
                    Console.WriteLine();
                    if (Function.MyGhostState(0).GetDoA())
                    {
                        s1 = 0;
                    }
                    else
                    {
                        s1 = 2;
                    }
                    if (Function.CanDR(Function.MyGhostState(s1).GetPos(), Direction.Down))
                    {
                        outdic.SI = s1; outdic.AL = Action_Label.Move; outdic.DR = Direction.Down;
                    }
                    else
                    {
                        switch (s1)
                        {
                        case 0:
                            if (Function.CanDR(Function.MyGhostState(s1).GetPos(), Direction.Left))
                            {
                                outdic.SI = s1; outdic.AL = Action_Label.Move; outdic.DR = Direction.Left;
                            }
                            break;

                        case 2:
                            if (Function.CanDR(Function.MyGhostState(s1).GetPos(), Direction.Right))
                            {
                                outdic.SI = s1; outdic.AL = Action_Label.Move; outdic.DR = Direction.Right;
                            }
                            break;
                        }
                    }

                    return(outdic);
                }
                else
                {
                    int tmp1 = cRandom.Next(0, global.GhostNum);
                    if (Function.MyGhostState(tmp1).GetDoA())
                    {
                        outdic.SI = tmp1; outdic.AL = Action_Label.Move;
                        while (true)
                        {
                            int tmp = cRandom.Next(0, 4);
                            if (Function.CanDR(Function.MyGhostState(tmp1).GetPos(), (Direction)tmp))
                            {
                                outdic.DR = (Direction)tmp; break;
                            }
                        }
                        break;
                    }
                }
            }
            return(outdic);
        }
Example #12
0
        public override Dicision Dicision()
        {
            Dicision outdic      = new Dicision();
            Random   cRandom     = new System.Random();
            var      delete_list = Function.GetDeleteEnemyNum();

            while (true)
            {
                int tmp1 = cRandom.Next(0, global.GhostNum);
                if (Function.MyGhostState(tmp1).GetDoA())
                {
                    outdic.SI = tmp1; outdic.AL = Action_Label.Move;
                    while (true)
                    {
                        int tmp = cRandom.Next(0, 4);
                        if (Function.CanDR(Function.MyGhostState(tmp1).GetPos(), (Direction)tmp))
                        {
                            outdic.DR = (Direction)tmp; break;
                        }
                    }
                    break;
                }
            }

            if (delete_list[1] >= 2)
            {
                var epos_list = Function.EnemyGhostState();
                for (int i = 0; i < global.GhostNum; i++)
                {
                    if (Function.MyGhostState(i).GetDoA())
                    {
                        Point mypos = Function.MyGhostState(i).GetPos();
                        for (int j = 0; j < epos_list.Count(); j++)
                        {
                            if ((epos_list[j].X == mypos.X + 1) && (epos_list[j].Y == mypos.Y))
                            {
                                if (Function.CanDR(mypos, Direction.Left))
                                {
                                    outdic.SI = i; outdic.AL = Action_Label.Move; outdic.DR = Direction.Left;
                                }
                            }
                            else if ((epos_list[j].X == mypos.X - 1) && (epos_list[j].Y == mypos.Y))
                            {
                                if (Function.CanDR(mypos, Direction.Right))
                                {
                                    outdic.SI = i; outdic.AL = Action_Label.Move; outdic.DR = Direction.Right;
                                }
                            }
                            else if ((epos_list[j].X == mypos.X) && (epos_list[j].Y == mypos.Y + 1))
                            {
                                if (Function.CanDR(mypos, Direction.Up))
                                {
                                    outdic.SI = i; outdic.AL = Action_Label.Move; outdic.DR = Direction.Up;
                                }
                            }
                            else if ((epos_list[j].X == mypos.X) && (epos_list[j].Y == mypos.Y - 1))
                            {
                                if (Function.CanDR(mypos, Direction.Down))
                                {
                                    outdic.SI = i; outdic.AL = Action_Label.Move; outdic.DR = Direction.Down;
                                }
                            }
                        }
                    }
                }
            }


            return(outdic);
        }