/// <summary>
 /// Constructor for the jtbvGameState class
 /// </summary>
 public jtbvGameState(jtbvTTYReader newTTY)
 {
     TTY = newTTY;
     player = new jtbvPlayerState();
     Mode = jtbvMode.UNKNOWN;
     FullRedrawRequested = true;
 }
예제 #2
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);
            }
        }