コード例 #1
0
        protected override void buildChildren(IState parent)
        {
            C4State state = (C4State)parent;

            for (int j = 0; j < state.Tab.GetLength(1); ++j)
            {
                for (int i = state.Tab.GetLength(0) - 1; i >= 0; --i)
                {
                    if (state.Tab[i, j] == 0)
                    {
                        C4State child = new C4State(state, i, j);
                        break;
                    }
                }
            }
        }
コード例 #2
0
 public C4State(C4State parent, int x, int y)
 {
     this.tab = new int[parent.tab.GetLength(0), parent.tab.GetLength(1)];
     Array.Copy(parent.tab, this.tab, this.tab.LongLength);
     this.isMaxMove = !parent.isMaxMove;
     this.tab[x, y] = this.isMaxMove?2:1;
     this.computeId();
     this.Parent = parent;
     parent.children.Add(this);
     this.Depth = parent.Depth + 0.5;
     if (parent.RootMove == null)
     {
         this.RootMove = id;
     }
     else
     {
         this.RootMove = parent.RootMove;
     }
     this.ComputeHeuristicGrade();
 }
コード例 #3
0
        private void move()
        {
            if (this.isPlayer)
            {
                if (this.state == 1)
                {
                    int column;


                    int correct;
                    do
                    {
                        correct = 0;

                        do
                        {
                            Console.WriteLine("Jaka kolumna?");
                            column = Convert.ToInt32(Console.ReadLine());
                        }                       while (column > this.board.GetLength(1));
                        if (this.board[0, column - 1] != 0)
                        {
                            correct = 1;
                        }
                        else
                        {
                            Console.Clear();
                        }
                        this.isPlayer = false;


                        for (int i = this.board.GetLength(0) - 1; i >= 0; --i)
                        {
                            if (this.board[i, column - 1] == 0)
                            {
                                this.board[i, column - 1] = 1;
                                break;
                            }
                        }
                    }                   while (correct != 0);


                    this.printBoard(false);
                }


                if (this.state == 2)
                {
                    C4State state = new C4State(board, this.isPlayer);

                    if (state.H == System.Double.PositiveInfinity)
                    {
                        this.result(1);
                    }

                    C4Search searcher = new C4Search(state, this.isPlayer, 2);
                    searcher.DoSearch();


                    C4State move = (C4State)searcher.Move;


                    if (move == null)
                    {
                        this.result(3);
                    }

                    this.board = move.Tab;

                    if (move.H == System.Double.NegativeInfinity)
                    {
                        this.result(2);
                    }

                    Console.Clear();
                    Console.WriteLine("Heurystyka: " + move.H);
                    this.isPlayer = false;
                }
            }
            else
            {
                C4State state = new C4State(board, this.isPlayer);
                if (state.H == System.Double.PositiveInfinity)
                {
                    this.result(1);
                }
                C4Search searcher = new C4Search(state, this.isPlayer, 2);
                searcher.DoSearch();
                C4State move = (C4State)searcher.Move;
                if (move == null)
                {
                    this.result(3);
                }
                this.board = move.Tab;
                if (move.H == System.Double.NegativeInfinity)
                {
                    this.result(2);
                }
                Console.Clear();
                Console.WriteLine("Heurystyka: " + move.H);
                this.isPlayer = true;
            }

            this.printBoard(false);
        }