public void AI()
        {
            if (gamestate == GameState.over)
            {
                return;
            }
            List <Te> posste = PossTe();

            if (posste.Count == 0)
            {
                throw new Exception("I can do nothing");
            }
            foreach (var te in posste)
            {
                Game game = Clone();
                te.Go(game);
                if (game.gamestate == GameState.over)
                {
                    te.Go(this); return;
                }
            }
            Te nextte = new Te(); int max = -big;

            foreach (var te in posste)
            {
                int p = Check(te, Clone(), 0);
                if (max < p)
                {
                    max    = p;
                    nextte = te;
                }
            }
            nextte.Go(this);
        }
        public List <Te> PossTe()
        {
            List <Te> posste = new List <Te>();
            Te        t      = new Te();

            foreach (TeState s in Enum.GetValues(typeof(TeState)))
            {
                for (int k = 0; k < 8; k++)
                {
                    for (int x = 0; x < 3; x++)
                    {
                        for (int y = 0; y < 4; y++)
                        {
                            t.state = s; t.k = k; t.X = x; t.Y = y;
                            if (t.IsValid(this))
                            {
                                posste.Add(t);
                            }
                        }
                    }
                }
            }
            return(posste);
        }
        public static int Check(Te te, Game game, int depth)
        {
            te.Go(game);
            if (game.gamestate == GameState.over)
            {
                return(big);
            }
            if (depth >= 1)
            {
                List <Koma> mochi = game.gamestate == GameState.turnB ? game.mochias : game.mochibs;
                int         res   = 0;
                foreach (var k in mochi)
                {
                    res += Point(k);
                }
                foreach (var k in game.onboards)
                {
                    if (k == null)
                    {
                        continue;
                    }
                    if (k.state == ((game.gamestate == GameState.turnB) ? KomaState.OnA : KomaState.OnB))
                    {
                        res += Point(k);
                    }
                }
                return(res);
            }

            int ans = big;

            var aitete = game.PossTe();

            if (depth > 0)
            {
                int c = 0; Te aitete0 = new Te();
                foreach (var te2 in aitete)
                {
                    int d = Check(te2, game.Clone(), big);
                    if (c < d)
                    {
                        c = d; aitete0 = te2;
                    }
                }
                aitete.Clear(); aitete.Add(aitete0);
            }

            foreach (var te2 in aitete)
            {
                int  res   = 0;
                Game game2 = game.Clone();
                te2.Go(game2);
                if (game2.gamestate == GameState.over)
                {
                    ans = 0; continue;
                }
                var jibunte = game2.PossTe();

                if (depth == 1)
                {
                    int c = 0; Te jibunte0 = new Te();
                    foreach (var te3 in jibunte)
                    {
                        int d = Check(te3, game2.Clone(), big);
                        if (c < d)
                        {
                            c = d; jibunte0 = te3;
                        }
                    }
                    jibunte.Clear(); jibunte.Add(jibunte0);
                }
                res = 0;
                foreach (var te3 in jibunte)
                {
                    int c = Check(te3, game2.Clone(), depth + 1);
                    if (res < c)
                    {
                        res = c;
                    }
                }
                ans = Math.Min(ans, res);
            }
            return(ans);
        }
 public List<Te> PossTe()
 {
     List<Te> posste = new List<Te>();
     Te t = new Te();
     foreach (TeState s in Enum.GetValues(typeof(TeState)))
         for (int k = 0; k < 8; k++)
             for (int x = 0; x < 3; x++)
                 for (int y = 0; y < 4; y++)
                 {
                     t.state = s; t.k = k; t.X = x; t.Y = y;
                     if (t.IsValid(this)) { posste.Add(t); }
                 }
     return posste;
 }
 public void AI()
 {
     if (gamestate == GameState.over) return;
     List<Te> posste = PossTe();
     if (posste.Count == 0)
     {
         throw new Exception("I can do nothing");
     }
     foreach (var te in posste)
     {
         Game game = Clone();
         te.Go(game);
         if (game.gamestate == GameState.over) { te.Go(this); return; }
     }
     Te nextte = new Te(); int max = -big;
     foreach (var te in posste)
     {
         int p = Check(te, Clone(), 0);
         if (max < p)
         {
             max = p;
             nextte = te;
         }
     }
     nextte.Go(this);
 }
        public static int Check(Te te, Game game, int depth)
        {
            te.Go(game);
            if (game.gamestate == GameState.over)
            {
                return big;
            }
            if (depth >= 1)
            {
                List<Koma> mochi = game.gamestate == GameState.turnB ? game.mochias : game.mochibs;
                int res = 0;
                foreach (var k in mochi) res += Point(k);
                foreach (var k in game.onboards)
                {
                    if (k == null) continue;
                    if (k.state == ((game.gamestate == GameState.turnB) ? KomaState.OnA : KomaState.OnB))
                    {
                        res += Point(k);
                    }
                }
                return res;
            }

            int ans = big;

            var aitete = game.PossTe();

            if (depth > 0)
            {
                int c = 0; Te aitete0 = new Te();
                foreach (var te2 in aitete)
                {
                    int d = Check(te2, game.Clone(), big);
                    if (c < d) { c = d; aitete0 = te2; }
                }
                aitete.Clear(); aitete.Add(aitete0);
            }

            foreach (var te2 in aitete)
            {
                int res = 0;
                Game game2 = game.Clone();
                te2.Go(game2);
                if (game2.gamestate == GameState.over) { ans = 0; continue; }
                var jibunte = game2.PossTe();

                if (depth == 1)
                {
                    int c = 0; Te jibunte0 = new Te();
                    foreach (var te3 in jibunte)
                    {
                        int d = Check(te3, game2.Clone(), big);
                        if (c < d) { c = d; jibunte0 = te3; }
                    }
                    jibunte.Clear(); jibunte.Add(jibunte0);
                }
                res = 0;
                foreach (var te3 in jibunte)
                {
                    int c = Check(te3, game2.Clone(), depth + 1);
                    if (res < c) { res = c; }
                }
                ans = Math.Min(ans, res);
            }
            return ans;
        }