Mach Tarok

A picture of the loading page

The loading page of MachTarok.com

MachTarok is a website designed to preserve and promote a traditional Czech card game, Taroky. Like all of my other projects, MachTarok was coded from scratch with almost no libraries or tools.

Server Structure

Since MachTarok was designed to be an online multiplayer game, the server is the most important part of the project. The main server file alone is nearly 4,000 lines of code, with other parts broken off into sub-files. The primary structure of the server is the Room-Player structure. When a player connects, they are prompted with a list of rooms which they can then join or leave. When a player is in a room, they can take actions within the current game inside that room. This structure is helpful to increase efficiency as players in one room are not communicating unnecessarily with players in another room.

The code itself is structured in a Main & Class style structure, where one main file hosts the server and manages clients while class files handle sub-processes like shuffling the deck or sorting hands. Effectively, this means the server is divided into many manageable pieces which are brought together for one cohesive experience.

Client Structure

The client structure is a lot more simplistic than the server structure. The client focuses primarily on messages received from the server and reactions to those messages. This allows a consistent experience and easily recovers from client lag by updating the client with the latest information. The client is also structured such that it can reload anytime without losing critical game information.

Much of the client HTML is built programmatically through JavaScript. The room cards, the deck and hands, and the GUI are all constructed modularly to allow for a wide range of possible uses. This means that, whether 1 or 1000 people are online, the client will be able to display the room cards. Additionally, this means that the user can quickly switch rooms to an entirely different set of rules and cards without difficulty.

Client-Server Communication

For an online multiplayer game, nothing is more important than client-server communication. This is why I chose to use SocketIO for this project. The client and server can send messages to each other quickly and efficiently.

The primary structure of the game is in actions. Each action is encoded in a message from the client to the server. The server then receives the action and sends back game information, which can then be used to decide upon the next action. In this way, the server can handle a game of many players or of players and robots, which are hosted on the server. With the Action-Information cycle established, it is relatively easy to implement new actions and return new pieces of information. The primary focus is on modularity.

Game Structure

The game of Taroky is structured as a series of steps taken in turns. Naturally, this is quite simply to translate into JavaScript. However, incorporating both human and robot players into the structure made things more difficult. I opted for an Action-Callback style game structure, where the game keeps track of which action is next and the client (or robot) takes the action. The game can then send a callback to the next player who must take an action, either through PlayerAction or RobotAction. In this way human and robot players can play seamlessly with each other.

The focus of the game structure was to allow for as little interruption to the players as possible. Because of the seamless system, any player can drop out of the game at any time and be instantly replaced by a robot without interrupting the other players. This system will also allow the incorporation of additional types of players, including AI.

Handling Exploits

In any client-server communication setting, there are always possible exploits that must be handled. The first and foremost focus of the MachTarok client-server communication is that Vanilla (unchanged) clients will have no issues competing with custom clients. Essentially, this means that every action taken by every player must be verified by the server to be correct before being processed, even if the Vanilla client could never attempt that action. Additionally, all information sent by the server to the clients cannot be private information. For example, the server should not send every player's hand information to every other player. The server, therefore, keeps track of which information is private and which is public and only sends information players should have.

Artificial Intelligence

Unlike more popular games, such as Chess, Taroky currently does not have any Artificial Intelligence programs designed to play it. I am designing, not one, but three such programs. These programs are incomplete, but more information can be found on GitHub.

The first, and most important, AI program will be a machine learning zero information style bot. It will play games alone, against itself, indefinitely and find the optimal strategy.

The second AI program will be the "human" AI, trained on all the moves by every human player on MachTarok.com

The third AI program is the custom-trained AI. Each player with an account will have a custom-trained AI designed to play as if it were that player. This AI will be used for two purposes:

  1. To train against a particular player when that player is unavailable
  2. To replace a player whenever that player drops out of a game mid-match

This revolutionary Taroky AI will allow many incredible possibilities, including playing against yourself. Unfortunately these AI are not yet available.