Exemplo n.º 1
0
        public override QState GetNewState(QAction action = null)
        {
            if (action.ToString() != "")
            {
                string[] point  = action.ToString().Split(',');
                Point    newPos = new Point(Convert.ToInt32(point[0]), Convert.ToInt32(point[1]));

                List <Point> newSpaces = openSpaces.ToList();
                newSpaces.Remove(newPos);

                List <Point> newMoves = myMoves.ToList();
                newMoves.Add(newPos);

                TicTacToe newState = new TicTacToe()
                {
                    myMoves = newMoves, yourMoves = yourMoves.ToList(), me = me, you = you, random = random, gui = gui, openSpaces = newSpaces, score = score
                };

                // Pass all variables to new state
                return(newState);
            }
            else
            {
                return(this);
            }
        }
Exemplo n.º 2
0
        public override QState GetNewState(QAction action = null)
        {
            if (action.ToString() != "")
            {
                string[] point = action.ToString().Split(',');
                Point newPos = new Point(Convert.ToInt32(point[0]), Convert.ToInt32(point[1]));

                List<Point> newSpaces = openSpaces.ToList();
                newSpaces.Remove(newPos);

                List<Point> newMoves = myMoves.ToList();
                newMoves.Add(newPos);

                TicTacToe newState = new TicTacToe() { myMoves = newMoves, yourMoves = yourMoves.ToList(), me = me, you = you, random = random, gui = gui, openSpaces = newSpaces, score = score };

                // Pass all variables to new state
                return newState;
            }
            else return this;
        }
Exemplo n.º 3
0
        public override void Step()
        {
            if (!HideOutput && maze != null)
            {
                try
                {
                    maze.SetSelf(self.X, self.Y);
                }
                catch (Exception e)
                {
                    WriteOutput("" + e, true);
                }
            }

            if (opponent.Any() && goal != self)
            {
                for (int i = 0; i < opponent.Count; i++)
                {
                    QState tempState = new Maze()
                    {
                        maze = maze, self = opponent[i], goal = self, width = width, height = height, walls = walls
                    };
                    QSearchResult opponentPath;
                    if (bestOpponentPath.ContainsKey(tempState))
                    {
                        opponentPath = bestOpponentPath[tempState];
                    }
                    else
                    {
                        opponentPath = new QSearch().AStar(tempState);
                        bestOpponentPath[tempState] = opponentPath;
                    }
                    if (opponentPath != null && opponentPath.Any())
                    {
                        int newX = opponent[i].X, newY = opponent[i].Y;

                        QAction action = opponentPath.actionsList.First();

                        if (random.NextDouble() > opponentDifficulty)
                        {
                            QAction[] allActions = tempState.GetActions();
                            action = allActions.ElementAt(random.Next(allActions.Length));
                        }

                        // Translate decision to new coordinate
                        if (action.ToString() == "up")
                        {
                            newY--;
                        }
                        else if (action.ToString() == "down")
                        {
                            newY++;
                        }
                        else if (action.ToString() == "left")
                        {
                            newX--;
                        }
                        else if (action.ToString() == "right")
                        {
                            newX++;
                        }

                        //WriteOutput("Moving adversary at " + opponent[i] + " " + action + " to "+newX+", "+newY+"...");
                        opponent[i] = new Point(newX, newY);
                        if (!HideOutput && maze != null)
                        {
                            maze.SetOpponent(i, newX, newY);
                        }
                    }
                }
            }

            if (goal == self)
            {
                score += 100;
            }
            else if (opponent.Contains(self))
            {
                score -= 100;
            }

            if (!HideOutput && CurrentMode == AWAKEN)
            {
                Thread.Sleep(100);
            }
        }