Exemple #1
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();
            }
        }