Exemplo n.º 1
0
 public jtbvGameAI(jtbvGameState State)
 {
     votes = new ArrayList();
     target = new Point();
     state = State;
     //currentAction;
 }
Exemplo n.º 2
0
        private jtbvTask ElectTask(jtbvGameState state)
        {
            jtbvTask retVal = null;

            votes.Clear();

            switch (state.Mode)
            {
                case jtbvMode.GAME:
                    if (state.CurrDlvl.Curiosities.Count > 0) // If we have questions about a dungeon feature
                    {
                        //Console.WriteLine("There are " + gameState.CurrDlvl.Curiosities.Count.ToString() + " requests in the curiosities list.");
                        Vote("INQUIRE_ABOUT", 80, (Point) state.CurrDlvl.Curiosities[0]);
                    }
                    if (state.Player.Hunger >= jtbvHungerStatus.WEAK)
                    {
                        Vote("FIX_HUNGER", 20 * (int) state.Player.Hunger);
                    }
                    if (state.CurrDlvl.DownStairsKnown())//) && (gameState.Player.Stats.Lvl > gameState.CurrentDepth))
                    {
                        Vote("DESCEND", 5);
                    }
                    if (state.CurrDlvl.GetDanger(state.Player.Loc) > 0)
                    {
                        Vote("ATTACK", 40);
                    }
                    if (state.Player.Stats.HP <= (state.Player.Stats.MaxHP / 3))
                    {
                        Vote("HEAL", 50);
                    }
                    if ((!state.ExcalCreated) && (state.Player.Stats.Lvl >= 5))
                    {
                        Vote("GET_EXCAL", 15);
                    }

                    if (state.CurrDlvl[state.Player.Loc].LowestAdjacentSearchValue() == 0)
                    {
                        Vote("SEARCH", 10);
                    }

                    Vote("EXPLORE", 8);
                    Vote("EXPLORE_SEARCH", 2);
                    Vote("WANDER", 1);
                    break;
                case jtbvMode.TEXT_PROMPT:
                    Vote("ANSWER_QUESTION", 100);
                    break;
                case jtbvMode.PROMPT:
                case jtbvMode.YN_PROMPT:
                    Vote("ANSWER_PROMPT", 100);
                    break;
                case jtbvMode.WINDOW_LIST:
                    Vote("ANSWER_QUESTION", 100);
                    break;
                case jtbvMode.DGAMELAUNCH:
                    Vote("DGAMELAUNCH_LOGIN", 100);
                    break;
                case jtbvMode.UNKNOWN:
                default:
                    break;
            }

            votes.Sort();
            votes.Reverse();

            if (votes.Count > 0)
            {
                int voteCnt = 0;

                while (voteCnt < votes.Count)
                {
                    jtbvActionVote choice = votes[voteCnt] as jtbvActionVote;

                    retVal = GetTask(choice);
                    retVal.State = state;

                    //Console.WriteLine("Voting trying to get '" + choice.ActionName + "'");

                    // TODO: Implement somthing like this.
                    if (retVal.CanExecute)
                    {
                        if (lastModeString != choice.ActionName)
                            Console.WriteLine(choice.ActionName);
                        else
                            Console.Write(".");

                        lastModeString = choice.ActionName;

                        break; // If that vote can execute, break out of the loop so that we keep this action.
                    }
                    voteCnt++;
                }

            }
            else
            {
                Console.WriteLine("ERROR! No votes cast!");
                retVal = null;
            }

            return retVal;
        }
Exemplo n.º 3
0
 private static void UpdatePlayerCursor(jtbvGameState state)
 {
     if (!state.MoreRequested)
     {
         if ((state.TTY.Cursor.Y >= 2) && (state.TTY.Cursor.Y < 21) &&
            (state.TTY.Cursor.X < 80))
         {
             state.Player.Loc = state.TTY.Cursor;
             state.Player.Loc.Y -= 2;
         }
     }
 }
Exemplo n.º 4
0
        public static void Main(string[] args)
        {
            jtbvITTYComm comm = new jtbvTelnetComm();
            jtbvTTYReader tty = new jtbvTTYReader();
            jtbvGameState gameState = new jtbvGameState(tty);
            jtbvGameAI gameAI = new jtbvGameAI(gameState);

            Console.WriteLine("Connecting...");
            comm.Connect("nethack.alt.org:23");
            // Send off the first ping to get stuff started.
            comm.Ping();

            while ((!comm.Timeout) && (!comm.PongReceived))
            {
                // Just wait for the pong to be received so that we can continue
                tty.ProcessTTY(comm.GetInput());

                // Process and clear the messages interpreted by the TTY
                gameState.ProcessMessages(tty.CurrentMessages);
                tty.ClearMessages();

                System.Threading.Thread.Sleep(10);
            }
            Console.WriteLine("First pong received");

            // We get the next input from the game (in this case it's Nethack) and pass it to the TTY processor
            tty.ClearMessages();
            tty.ProcessTTY(comm.GetInput());

            // Process and clear the messages interpreted by the TTY
            gameState.ProcessMessages(tty.CurrentMessages);

            while (!comm.Timeout)
            {
                foreach (string nextCmd in gameAI)
                {
            //					Console.WriteLine("Sending '" + nextCmd + "'");

                    comm.Send(nextCmd); // Send our next move
                    comm.Ping();		// Ping and wait for the next Pong to be receieved so that we can repeat the process all over again.

                    // After we send each move to the comm, we ping the comm and wait
                    // for a pong to return to us. We know that the game has processed
                    // our move and sent back all pertinent messages if we receieve
                    // the pong. So here, we check to see if we got a pong. If so, we
                    // pass the messages into the game processor.
                    while ((!comm.Timeout) && (!comm.PongReceived))
                    {
                        // First, we get the next input from the game (in this case it's Nethack) and pass it to the TTY processor
                        tty.ProcessTTY(comm.GetInput());

                        // Process and clear the messages interpreted by the TTY
                        gameState.ProcessMessages(tty.CurrentMessages);
                        tty.ClearMessages();

                        System.Threading.Thread.Sleep(10);
                    }
                }

                UpdatePlayerCursor(gameState);
            }
        }