Esempio n. 1
0
        private void cellClick(object sender, EventArgs e)
        {
            if (!humans_turn)
            {
                return;
            }
            PictureBox p   = sender as PictureBox;
            int        tag = (int)p.Tag;



            if (frontier.Find(f => f.pos == tag).flipped == null) // not a valid move
            {
                return;
            }
            foreach (var x in frontier)
            {
                board[x.pos].BackgroundImage = null;
                board[x.pos].Refresh();
            }
            game = game.make_move(frontier.Find(f => f.pos == tag));
            display_state();
            computer_score.Text = game.black.Count.ToString();
            your_score.Text     = game.white.Count.ToString();

Computer:

            humans_turn    = false;
            turn.Text      = "Computer's turn!";
            turn.ForeColor = Color.Maroon;
            turn.Invalidate();
            turn.Update();
            computer_move();
            display_state();
            computer_score.Text = game.black.Count.ToString();
            your_score.Text     = game.white.Count.ToString();

            frontier = game.get_frontier(true);
            if (frontier == null)
            {
                if (game.game_over())
                {
                    gameover();
                    return;
                }
                MessageBox.Show("you have no moves"); //you have no moves

                goto Computer;
            }
            foreach (var x in frontier)
            {
                board[x.pos].BackgroundImage = Properties.Resources.hint;
            }
            humans_turn    = true;
            turn.Text      = "Your turn!";
            turn.ForeColor = Color.Green;
        }
Esempio n. 2
0
        int alphabeta(reversi st, int depth, int α, int β, bool maximizing_player)
        {
            var frontier = st.get_frontier(maximizing_player);

            if (depth == 0 || frontier == null)
            {
                return(st.eval_state(maximizing_player));
            }
            possible_move bm;

            if (!maximizing_player)
            {
                int v = -100000;
                foreach (var pos in frontier)
                {
                    bm = pos;
                    reversi child = st.make_move(pos);
                    v = Math.Max(v, st.alphabeta(child, depth - 1, α, β, !maximizing_player));
                    α = Math.Max(α, v);
                    if (β <= α)
                    {
                        break;// (*β cut - off *)
                    }
                }
                return(v);
            }
            else
            {
                int v = 100000;
                foreach (var pos in frontier)
                {
                    bm = pos;
                    reversi child = st.make_move(pos);
                    v = Math.Min(v, st.alphabeta(child, depth - 1, α, β, !maximizing_player));
                    β = Math.Min(β, v);
                    if (β <= α)
                    {
                        break;// (*β cut - off *)
                    }
                }
                return(v);
            }
        }