override public void selectMove(RLAgent curPlayer)
    {
        this.curPlayer = curPlayer;

        KeyValuePair <IntPair, IntPair> selectedMoves = selectNextMoves();

        IntPair bestMove     = selectedMoves.Key;
        IntPair selectedMove = selectedMoves.Value;

        if (!selectedMove.isNone())
        {
            game.makeMove(selectedMove.X, selectedMove.Y, curPlayer.Val);
            lastMove.X = selectedMove.X;
            lastMove.Y = selectedMove.Y;
            learn();
        }
        else
        {
            // StateAction Pair that got us here in the first place.
            int     prevState      = game.GetState(lastMove.X, lastMove.Y, true);     // switch to previous state before move
            int     curState       = game.GetState();
            IntPair curStateAction = new IntPair(prevState, curState);
            double  curQVal        = getQ(curStateAction);
            double  r = 0.0f;
            rewardDelegate(game.getWinner(), out r);         // This state winner
            double nextMaxQ = getQS(curQVal, r);             //getQ(nextBestStateAction);
            updateQ(curStateAction, curQVal, nextMaxQ, r, alpha);
        }
    }
Esempio n. 2
0
        public void DrawAgent(RLMap map, RLAgent agent, int x, int y)
        {
            RLCell oldCell = map.Cells.Where(c => c.X == agent.locationX && c.Y == agent.locationY).FirstOrDefault();
            oldCell.Unoccupied = true;
            Console.SetCursorPosition(oldCell.X, oldCell.Y);
            Console.ForegroundColor = ConsoleColor.White;
            Console.Write(oldCell.DisplayCharacter);

            Console.SetCursorPosition(x, y);
            Console.ForegroundColor = agent.DisplayColor;
            Console.Write(agent.DisplayChar);
            Console.ForegroundColor = ConsoleColor.White;
            map.Cells.Where(c => c.X == x && c.Y == y).FirstOrDefault().Unoccupied = false;
        }
Esempio n. 3
0
    public override void _Ready()
    {
        energyLabel = GetNode(energyLabelOutput) as Label;
        stepsLabel  = GetNode(stepsLabelPath) as Label;
        rewardLabel = GetNode(rewardLabelPath) as Label;

        agent = GetNode(agentPath) as RLAgent;

        sensor = GetNode(energySensor) as EnergySensor;
        sensor.Subscribe(this);

        energyLabel.Text = sensor.CurrentEnergy + "";
        stepsLabel.Text  = "Elapsed Time: " + agent.CurrentStep;
        rewardLabel.Text = "Reward: " + 0;

        agent.AddResetListener(this);
    }
Esempio n. 4
0
        public bool CanSeeEachOther(RLAgent first, RLAgent second, RLMap map)
        {
            Func<int, int> moveTowardsX = null;
            Func<int, int> moveTowardsY = null;

            if (first.locationX > second.locationX)
            {
                moveTowardsX = x => x - 1;
            }
            else
            {
                moveTowardsX = x => x + 1;
            }

            if (first.locationY > second.locationY)
            {
                moveTowardsY = y => y - 1;
            }
            else
            {
                moveTowardsY = y => y + 1;
            }

            int checkX = first.locationX;
            int checkY = first.locationY;

            do
            {
                checkX = (checkX != second.locationX) ? moveTowardsX(checkX) : checkX;
                checkY = (checkY != second.locationY) ? moveTowardsY(checkY) : checkY;

                var cellToCheck = map.Cells.Where(c => c.X == checkX && c.Y == checkY).FirstOrDefault();

                if (!cellToCheck.Transparent)
                {
                    return false;
                }
            } while (second.locationX != checkX || second.locationY != checkY);

            return true;
        }
Esempio n. 5
0
 abstract public void selectMove(RLAgent curPlayer);
Esempio n. 6
0
        public Tuple<int, int> moveRandom(RLAgent agent)
        {
            int direction = _dice.RollD4();
            int x = agent.locationX, y = agent.locationY;

            switch (direction)
            {
                case 1:
                    //north
                    y = agent.locationY - 1;
                    break;
                case 2:
                    //south
                    y = agent.locationY + 1;
                    break;
                case 3:
                    //east
                    x = agent.locationX - 1;
                    break;
                case 4:
                    //west
                    x = agent.locationX + 1;
                    break;
                default:
                    break;
            }

            return new Tuple<int, int>(x, y);
        }