Exemplo n.º 1
0
        public async Task <string> GetMove()
        {
            DateTime beginFunction = DateTime.Now;

            gameboard = game.GetCopyOfGameBoard();
            GameTreeNode testroot       = new GameTreeNode(null, gameboard);
            DateTime     start          = DateTime.Now;
            int          levelsTraveled = 0;
            String       move           = "";

            game.Board = gameboard;

            for (int i = 3; (DateTime.Now - start).TotalSeconds < 5.6; i++)
            {
                testroot     = new GameTreeNode(null, gameboard);
                game.Board   = gameboard;
                finishedTree = true;
                await expandTree(testroot, i + 1, 1, start, DateTime.Now);

                if (finishedTree)
                {
                    move           = chosenMove;
                    levelsTraveled = i;
                }
            }
            game.Board = gameboard;
            testroot   = new GameTreeNode(null, gameboard);
            return(move);
        }
Exemplo n.º 2
0
 public HardAI(Game g)
 {
     gameboard = g.GetCopyOfGameBoard();
     game = g;
 }
Exemplo n.º 3
0
 public HardAI(Game g)
 {
     gameboard = g.GetCopyOfGameBoard();
     game      = g;
 }
Exemplo n.º 4
0
        public string GetMove()
        {
            gameboard = game.GetCopyOfGameBoard();
            string results  = "B";
            bool   madeMove = false;

            foreach (Tile t in gameboard.Tiles)
            {
                if (t.Points == 6 && (t.NumOfRedMarbles > t.NumOfBlueMarbles))
                {
                    foreach (Hole h in t.Holes)
                    {
                        if (h.CanBePlayed)
                        {
                            results += h.Coord.Row.ToString() + h.Coord.Col.ToString();
                            madeMove = true;
                            break;
                        }
                    }
                }
                if (madeMove)
                {
                    break;
                }
            }

            if (!madeMove)
            {
                foreach (Tile t in gameboard.Tiles)
                {
                    if (t.Points == 4 && (t.NumOfRedMarbles > t.NumOfBlueMarbles))
                    {
                        foreach (Hole h in t.Holes)
                        {
                            if (h.CanBePlayed)
                            {
                                results += h.Coord.Row.ToString() + h.Coord.Col.ToString();
                                madeMove = true;
                                break;
                            }
                        }
                    }
                    if (madeMove)
                    {
                        break;
                    }
                }
            }

            if (!madeMove)
            {
                foreach (Tile t in gameboard.Tiles)
                {
                    if (t.Points == 3 && (t.NumOfRedMarbles > t.NumOfBlueMarbles))
                    {
                        foreach (Hole h in t.Holes)
                        {
                            if (h.CanBePlayed)
                            {
                                results += h.Coord.Row.ToString() + h.Coord.Col.ToString();
                                madeMove = true;
                                break;
                            }
                        }
                    }
                    if (madeMove)
                    {
                        break;
                    }
                }
            }

            if (!madeMove)
            {
                foreach (Tile t in gameboard.Tiles)
                {
                    if (t.Points == 2 && (t.NumOfRedMarbles > t.NumOfBlueMarbles))
                    {
                        foreach (Hole h in t.Holes)
                        {
                            if (h.CanBePlayed)
                            {
                                results += h.Coord.Row.ToString() + h.Coord.Col.ToString();
                                madeMove = true;
                                break;
                            }
                        }
                    }
                    if (madeMove)
                    {
                        break;
                    }
                }
            }

            if (!madeMove)
            {
                int currentRow        = 0;
                int currentCol        = 0;
                int currentPointValue = 0;

                foreach (Tile t in gameboard.Tiles)
                {
                    foreach (Hole h in t.Holes)
                    {
                        if (h.CanBePlayed && (t.Points > currentPointValue))
                        {
                            currentRow        = h.Coord.Row;
                            currentCol        = h.Coord.Col;
                            currentPointValue = t.Points;
                        }
                    }
                }
                results += currentRow.ToString() + currentCol.ToString();
            }

            return(results);
        }