mjaiのC++ひな形(ツモ切りAI)

とりあえず動いてる。

main.cpp

#include <iostream>
#include <vector>
#include <algorithm>
#include <initializer_list>

#include "lib/socket.h"
#include "lib/bakkjson.hpp"

using namespace std;

typedef json::value::object object;

void run(string host, int port, string room) {

  cerr << "connecting..." << endl;
  gimite::socket_stream sock(host, port);
  if(!sock) {
    cerr << "failed to connect." << endl;
    return;
  }

  cerr << "starting..." << endl;

  string line;
  int id;

  while(getline(sock, line)) {
    cerr << "<-\t" << line << endl;
    json::value action = json::parse(line);
    
    string type = action["type"];
    json::value response;
    if(type == "hello") {
      response = object({{"type", "join"}, {"name", "silica"}, {"room", room}});
    }
    else if(type == "start_game") {
      id = action["id"];
      response = object({{"type", "none"}});
    }
    else if(type == "end_game") break;
    else if(type == "tsumo") {
      if ((int)action["actor"] == id) {
        response = object({{"type", "dahai"}, {"actor", id}, {"pai", action["pai"]}, {"tsumogiri", true}});
      }
      else response = object({{"type", "none"}});
    }
    else if(type == "error") {
      cerr << "ERROR!" << endl;
      break;
    }
    else response = object({{"type", "none"}});

    cerr << "->\t" << response << endl;
    sock << response << endl;
  }
}

int main() {

  gimite::startup_socket();

  run("localhost", 11600, "default");

  gimite::cleanup_socket();

  return 0;
}

lib/socket.h (http://gimite.net/gimite/cppmess.htm)
lib/bakkjson.hpp
lib/bakkjson.cpp