Ejemplo n.º 1
0
        internal bool ProcessMessageString(IClueAI ai, string s)
        {
            var trimmed = s.Replace("\0", "");
              string[] pieces = trimmed.Split(' ');
              var opcode = pieces[0];

              switch (opcode)
              {
            case "done":
              return true;
            case "reset":
              var cards = Parser.ParseCards(pieces.Skip(3));
              ai.Reset(Parser.ParseInt(pieces[1]), Parser.ParseInt(pieces[2]), cards.Suspects, cards.Weapons, cards.Rooms);
              SendOK();
              break;
            case "suggestion":
              {
            var suggester = Parser.ParseInt(pieces[1]);
            var murderSet = Parser.ParseSet(pieces.Skip(2).Take(3));
            var disprover = Parser.ParseIntMaybe(pieces[5]);
            var disproof = (pieces.Length == 7) ? Parser.ParseCard(pieces[6]) : null;
            ai.Suggestion(suggester, murderSet, disprover, disproof);
            SendOK();
            break;
              }
            case "accusation":
              {
            var accuser = Parser.ParseInt(pieces[1]);
            var murderSet = Parser.ParseSet(pieces.Skip(2).Take(3));
            var won = Parser.ParseBool(pieces[5]);
            ai.Accusation(accuser, murderSet, won);
            SendOK();
            break;
              }
            case "suggest":
              {
            var suggestion = ai.Suggest();
            Send("suggest " + suggestion.ToString());
            break;
              }
            case "accuse":
              {
            var accusation = ai.Accuse();
            Send(accusation == null
                   ? "-"
                   : "accuse " + accusation.ToString()
              );
            break;
              }
            case "disprove":
              {
            var player = Parser.ParseInt(pieces[1]);
            var suggestion = Parser.ParseSet(pieces.Skip(2).Take(3));
            var disproof = ai.Disprove(player, suggestion);
            Send(disproof == null
                   ? "-"
                   : "show " + disproof.ToString()
              );
            break;
              }
            default:
              throw new ArgumentException("Bogus message: " + string.Join("|", pieces));
              }
              return false;
        }
Ejemplo n.º 2
0
        internal bool ProcessMessageString(IClueAI ai, string s)
        {
            var trimmed = s.Replace("\0", "");

            string[] pieces = trimmed.Split(' ');
            var      opcode = pieces[0];

            switch (opcode)
            {
            case "done":
                return(true);

            case "reset":
                var cards = Parser.ParseCards(pieces.Skip(3));
                ai.Reset(Parser.ParseInt(pieces[1]), Parser.ParseInt(pieces[2]), cards.Suspects, cards.Weapons, cards.Rooms);
                SendOK();
                break;

            case "suggestion":
            {
                var suggester = Parser.ParseInt(pieces[1]);
                var murderSet = Parser.ParseSet(pieces.Skip(2).Take(3));
                var disprover = Parser.ParseIntMaybe(pieces[5]);
                var disproof  = (pieces.Length == 7) ? Parser.ParseCard(pieces[6]) : null;
                ai.Suggestion(suggester, murderSet, disprover, disproof);
                SendOK();
                break;
            }

            case "accusation":
            {
                var accuser   = Parser.ParseInt(pieces[1]);
                var murderSet = Parser.ParseSet(pieces.Skip(2).Take(3));
                var won       = Parser.ParseBool(pieces[5]);
                ai.Accusation(accuser, murderSet, won);
                SendOK();
                break;
            }

            case "suggest":
            {
                var suggestion = ai.Suggest();
                Send("suggest " + suggestion.ToString());
                break;
            }

            case "accuse":
            {
                var accusation = ai.Accuse();
                Send(accusation == null
                   ? "-"
                   : "accuse " + accusation.ToString()
                     );
                break;
            }

            case "disprove":
            {
                var player     = Parser.ParseInt(pieces[1]);
                var suggestion = Parser.ParseSet(pieces.Skip(2).Take(3));
                var disproof   = ai.Disprove(player, suggestion);
                Send(disproof == null
                   ? "-"
                   : "show " + disproof.ToString()
                     );
                break;
            }

            default:
                throw new ArgumentException("Bogus message: " + string.Join("|", pieces));
            }
            return(false);
        }