ColorShapeLinks: A Board Game AI Competition for Educators and Students

ColorShapeLinks is an AI board game competition framework specially designed for students and educators in videogame development, with openness and accessibility in mind. The competition is based on an arbitrarily-sized version of the Simplexity board game, the motto of which,"simple to learn, complex to master", is curiously also applicable to AI agents. ColorShapeLinks offers graphical and text-based frontends and a completely open and documented development framework built using industry standard tools and following software engineering best practices. ColorShapeLinks is not only a competition, but both a game and a framework which educators and students can extend and use to host their own competitions.


Introduction
ColorShapeLinks is an artificial intelligence (AI) competition framework for the Simplexity board game (Brain Bender Games, 2009) with arbitrary dimensions. It is a similar game to Connect-4, with pieces defined not only by color, but also by shape.
The ColorShapeLinks development framework offers Unity (Unity Technologies, 2020) and .NET Core console frontends. Agents are implemented in C# and run unmodified in either frontend. Unity and C# are widely used in the games industry (Toftedahl & Engström, 2019) and for game development education (Dickson, 2015;Comber et al., 2019;Fachada & Códices, 2020), making the competition especially accessible to this audience. The framework is open source, fully documented and developed following best practices in software engineering, allowing it to be studied and extended by educators, researchers and students alike. Furthermore, it contains all the tooling for setting up competitions, allowing it to be used as-is for internal competitions in AI courses, for example, or even as the basis for international AI competitions, as was indeed the case in the 2020 IEEE Conference on Games (IEEE CoG 2020). In this regard, ColorShapeLinks is not simply a software tool that uses AI technologies for educational purposes (Chen et al., 2020), but a software toolkit to both teach and learn board game AI.
This paper is organized as follows. In Section 2, the state of the art in board game AI -and how ColorShapeLinks fits in -is briefly discussed. The ColorShapeLinks board game and its original version, Simplexity, are characterized in Section 3. The development framework, in particular the existing frontends, its architecture, the basics of implementing an AI agent and included agents are presented in Section 4. In Section 5, we describe how the ColorShapeLinks framework was used to host two internal competitions in an AI course unit, as well as a fully-fledged international AI competition in the IEEE CoG 2020 conference. The paper closes with Section 6, in which we present some conclusions.

Background
Computer programs for playing classical board games such as Chess, Draughts or Go, were the first known application of AI for games (Millington, 2019). AI research in games has subsequently grown far beyond the domain of board games (Yannakakis & Togelius, 2018). Nonetheless, these continue to be a focus of active research, not only in AI techniques for playing particular games -e.g., Go (Silver et al., 2016) -but also for playing board games in general (Konen, 2019;Kowalski et al., 2019;Piette et al., 2019) or even creating new ones Kowalski & Szyku la, 2016). Furthermore, new board game AI challenges and competitions continue to be proposed (Justesen et al., 2019).
While board games are probably one of the easiest ways to introduce AI for games to students, state-of-the-art board game AI research is gaining some distance from both industry and education in videogame development. Requirements such as general game playing capabilities for the AI, knowledge of general game specification languages, or complex and multilayered tooling can raise the entry level for newcomers, potentially discouraging prospective participants which could otherwise bring new ideas to academia -or at least get involved in its processes.
ColorShapeLinks aims to reduce this gap by offering an approachable, open and flexible AI competition for the videogame development education audience. This is accomplished by making the development of an AI agent for ColorShapeLinks very simple (e.g., write a single method and test it in Unity), though allowing for considerable customization via a modular framework architecture, which enables games and full tournaments to run without Unity. While accessible for undergraduates and non-specialist game developers, ColorShapeLinks provides a challenging and intricate board game competition, addressable with vastly different techniques, from knowledge-based methods (Allis, 1988) to machine learning techniques (Silver et al., 2016) or anything in between.
It should be noted that Simplexity and ColorShapeLinks could be implemented under a general game playing system such as RBG (Kowalski et al., 2019) or Ludii , and this would probably be an excellent exercise. However, using these frameworks would mean losing some of the educational advantages offered by Color-ShapeLinks, namely accessibility, openness (e.g., Ludii is not open source at the time of (a) White wins with white pieces.
(b) White wins with round pieces.
(c) Red wins with red pieces.
(d) Red wins with square pieces. writing) and keeping the focus on general game design and development education while providing students with a broad AI for games background.

ColorShapeLinks
ColorShapeLinks is a version of the Simplexity board game with arbitrary and parameterizable dimensions. In this section we describe both Simplexity and ColorShapeLinks, highlighting their computational aspects, as well as our motivation for building a competition framework based on this game.

The Simplexity Board Game
The Simplexity board game is similar to Connect-4 in two regards: 1) the first player to place four pieces of a given type in a row wins; and, 2) the base board size is 6×7. The crucial difference is that, in Simplexity, pieces are defined not only by color, but also by shape -round or square. Player 1, white, wins if it can connect either four round pieces or four white pieces. Likewise for player 2, red, but with square or red pieces. Players begin with 21 pieces of their color, 11 of which square, and the remaining 10 round. The catch here is that shape has priority over color as a winning condition. Therefore, a player can lose in its turn when placing a piece of the opponent's winning shape. Table 1 summarizes these rules and Figure 1 shows the possible winning conditions.

The ColorShapeLinks Board Game
ColorShapeLinks is a Simplexity game parameterizable with respect to board dimensions, number of pieces required for a winning sequence, and initial number of round and square pieces. Table 2 shows the available parameters as well as the symbols used for them for the remainder of this paper. 3  Round pieces per player 10 a i.e., a regular game of Simplexity.
• It is a two-player zero-sum adversarial game.
• It is deterministic, i.e., there is no random element influencing the game state.
• It has perfect information, i.e., the board state is fully observable.
• The maximum number of turns is given by i.e., it is equal to the minimum between the number of board positions, r · c, and the total pieces available to be played, 2(s + o).
• Since each board position can be in one of five states (empty, white circle, white square, red circle or red square), an upper bound for the state space is given by 5 tmax . In practice the state space will be considerably smaller, since this value includes invalid states, for example when pieces are on top of empty cells.
• The initial branching factor is 2 × c (2 shapes, c columns), although it may decrease during the game as columns are filled and pieces of a certain shape are played-out. Consequently, an upper bound for the game tree size is given by (2 · c) tmax . 4 These characteristics place ColorShapeLinks in an interesting position for AI research. The game, even with standard Simplexity parameters, cannot currently be solved using a brute force approach in a short amount of time. Like most games nowadays, machine learning techniques (e.g., deep learning) together with a tree search approach such as Monte Carlo Tree Search (MCTS) (Coulom, 2007), for example, will certainly be able to produce hard to beat agents. However, the limited and well-defined ruleset leaves the door open for knowledge-based or even analytical solutions.

Motivation
ColorShapeLinks was originally developed as a Unity-only assignment for an AI course unit 1 at Lusófona University Videogames BA (Fachada & Códices, 2020). Given the variety of student backgrounds in the BA (de Andrade & Fachada, 2020), the project had to be made accessible for everyone, while challenging for more advanced students. A deterministic, fully observable two-player, non-trivial board game was an obvious choice. Another requirement was that it was not a very well-known game, so that not much AI code is available online, forcing students to be original. Simplexity (Brain Bender Games, 2009) ticks those boxes, as it was only used once in an AI course (Wilkins, 2012), to our knowledge. Furthermore, Simplexity was implemented as a console C# project (no AI) two years prior 2 , and as such, was a perfect choice, given that students already know the game.
Given the fact that Unity is used in education (Dickson, 2015;Dickson et al., 2017;Hmeljak, 2020;Comber et al., 2019;Fachada & Códices, 2020) and that C# is used as a scripting language in several major game engines (Unity Technologies, 2020; Silicon Studio, 2019; Crytek, 2019; Linietsky & Manzur, 2019; Williams & Spilman, 2019), and while neither of these is very common in game AI competitions, ColorShapeLinks hopes to reduce the gap between academia and game development industry/education.
In sum, building an AI agent for ColorShapeLinks is very simple, asking only the implementer to extend a class and implement one method. A basic Minimax algorithm with a simple heuristic can be implemented in less than 30 minutes. Educators can use it to demonstrate how to create a simple agent from scratch, during a class for example, and leave up to the students to find better, more efficient solutions. This can be done as an assignment, a competition, or both.

Overview
The ColorShapeLinks development framework offers two application frontends, one for the Unity game engine, the other a text-based affair aimed at terminal use. This allows students familiar with Unity to start implementing an agent from their comfort zone, advancing to the text-based console frontend if Unity development limitations begin to show. Advanced students or researchers can skip the Unity frontend altogether, and start with the console frontend from the offset.

ConsoleApp frontend
UnityApp frontend App Lib UnityApp Common The development framework is available at https://github.com/VideojogosL usofona/color-shape-links-ai-competition and is fully open source, licensed under the Mozilla Public License 2.0 3 (MPL2), which requires changes to the source code to be shared, although allowing for integration with proprietary code if the MPL2 licensed code is kept in separate files. The framework is completely documented and the documentation is available at https://videojogoslusofona.github.io/color-shape -links-ai-competition/docs/html/.

Architecture
The development framework is organized around three main components, namely the Unity frontend (UnityApp, a single .NET/Mono project), the console frontend (Con-soleApp, composed of two .NET projects), and the Common .NET project. This organization is shown in Figure 2, and discussed with additional detail in the following paragraphs.

The Common Project
The Common project is a .NET Standard 2.0 class library which constitutes the core of the framework. It defines the fundamental models-from a Model-View-Controller (MVC) perspective (Krasner & Pope, 1988)-of the ColorShapeLinks game, such as the board, its pieces or performed moves, and is a dependency of the remaining projects. It is further subdivided in the AI and Session namespaces. The former defines AI-related abstractions, such as the AbstractThinker class, which AI agents must extend, as well as a manager for finding and instantiating concrete AI agents. The latter specifies a number of match and session-related interfaces, as well as concrete match and session (i.e., tournament) models.

The ConsoleApp Frontend Projects
The ConsoleApp is composed of two .NET projects, App and Lib, both of which depend on the Common class library, as shown in Figure 2. The App project is a .NET Core console application with an internal dependency on the Lib project, itself a .NET Standard 2.0 class library. The App project provides the actual console frontend, namely the text user interface (TUI) with which the user interacts in order to run ColorShapeLinks matches and sessions.
The Lib class library acts as an UI-independent "game engine", offering match and session controllers, as well as interfaces for the associated event system, allowing to plugin renderers (views, in MVC parlance) or other event handling code at runtime. It serves as a middleware between the Common library and frontend applications, such as the one implemented in the App project. It is not used by the Unity implementation, since Unity already provides its own game engine logic, forcing match and session controllers to be tightly integrated with its frame update cycle. Nonetheless, the Lib class library makes the creation of new ColorShapeLinks TUIs or GUIs very simple, as long as they are not based on highly prescriptive frameworks such as Unity.

The UnityApp Frontend Project
The UnityApp is a ColorShapeLinks frontend implemented in the Unity game engine. Like the ConsoleApp, it is designed around the MVC design pattern, making use of the models provided by the Common library. In this case, however, the views and controllers are tightly integrated with the Unity engine.

Frontends
The two available frontends, for Unity and console, have similar capabilities. Both are capable of performing matches and tournaments involving multiple AI agents and human players. An agent can be used without modification when moving from one frontend to the other. There are, however, advantages in using the console frontend. The following paragraphs offer additional detail on each frontend.

The Unity Frontend
In the Unity frontend, matches and tournaments are played within the Unity Editor, though it is possible to create a standalone build with prefixed match or tournament configurations. The rationale behind this choice is that ColorShapeLinks is at its core a development framework. As such, it makes sense this is done within the Unity Editor, which is a development environment. A game of ColorShapeLinks running within the Unity Editor is shown in Figure 3.
Developing an agent within Unity has the disadvantage that games run considerably slower than in the console. This is to be expected: games run slower inside the editor. Furthermore, constantly creating builds with prefixed configurations is not practical. Therefore, while this frontend makes ColorShapeLinks approachable, it should be considered more of an introduction to the competition than a definitive way of implementing advanced state-of-the-art ColorShapeLinks agents.

The Console Frontend
The console UI allows for a more refined control of ColorShapeLinks matches and sessions. Being based on MVC, it allows for easily swapping the UI, as well as running matches at full speed, contrary to the Unity editor. Figure 4 shows running a Color-ShapeLinks match using the console UI.
While the console frontend offers many extensibility points, its default configuration will likely suffice in most situations. For example, users can run a learning algorithm on

Implementing an Agent
The first step to implement an AI agent is to extend the AbstractThinker base class. This class has three overridable methods, but it is only mandatory to override one of them, as shown in Table 3.
There is also the non-overridable OnThinkingInfo() method, which can be invoked for producing "thinking" information, mainly for debugging purposes. In the Unity frontend this information is printed on Unity's console, while in the console frontend the information is forwarded to the registered thinker listeners (or views, from a MVC perspective).
Classes extending AbstractThinker also inherit a number of useful read-only properties, namely board and match configuration properties (number of rows, number of columns, number of pieces in sequence to win a game, number of initial round pieces per player and number of initial square pieces per player) and the time limit for the AI to play. Concerning the board/match configuration properties, these are also available in the board object given as a parameter to the Think() method. However, the Setup() method can only access them via the inherited properties.
The following subsections address the overriding of each of these three methods.

Overriding the Setup() method
If an AI agent needs to be configured before starting to play, the Setup() method is the place to do it. This method receives a single argument, a string, which can contain agent-specific parameters, such as maximum search depth, heuristic to use, and so on. It is the agent's responsibility to parse this string. In the Unity frontend, the string is specified in the "Thinker params" field of the AIPlayer component. When using the console frontend, the string is passed via the --white/red-params option for simple matches, or after the agent's fully qualified name in the configuration file of a complete session. Besides the parameters string, the Setup() method also has access to board/match properties inherited from the base class.
The same AI agent can represent both players in matches, as well as more than one player in sessions/tournaments. Additionally, separate instances of the same AI agent can be configured with different parameters. In such a case it might be useful to also override the ToString() method for discriminating between the instances configured differently. This is an essential feature if ColorShapeLinks is running under a machine learning and/or optimization infrastructure.
Note that concrete AI agents require a parameterless constructor in order to be found by the various frontends. Such constructor exists by default in C# classes if no other constructors are defined. However, it is not advisable to use a parameterless constructor to setup an AI agent, since the various board/match properties will not be initialized at that time. This is yet another good reason to perform all agent configuration tasks in the Setup() method. In any case, concrete AI agents do not need to provide an implementation of this method if they are not parameterizable or if they do not require an initial configuration step.

Overriding the Think() method
The Think() method is where the AI actually does its job and is the only mandatory override when extending the AbstractThinker class. This method accepts the game board and a cancellation token, returning a Future-Move object. In other words, the Think() method accepts the game board, the AI decides the best move to perform, and returns it. The selected move will eventually be executed by the match engine.
The Think() method is called in a separate thread. As such, it should only access local instance data. The main thread may ask the AI to stop thinking, for example if the thinking time limit has expired. Thus, while thinking, the AI should frequently test if a cancellation request was made to the cancellation token. If so, it should return immediately with no move performed.
The game board can be freely modified within the Think() method, since this is a copy and not the original game board being used in the main thread. More specifically, the agent can try moves with the DoMove() method, and cancel them with the UndoMove() method. The board keeps track of the move history, so the agent can perform any sequence of moves, and roll them back afterwards. For parallel implementations, the agent can create additional copies of the board, one per thread, so that threads can search independently of each other.
The CheckWinner() method of the game board is useful to determine if there is a winner. If there is one, the solution is placed in the method's optional parameter. For building heuristics, the game board's public read-only variable winCorridors will probably be useful. This variable is a collection containing all corridors (sequences of positions) where promising or winning piece sequences may exist.
The AI agent will lose the match in the following situations: • Causes or throws an exception.
• Takes too long to play.
• Returns an invalid move.

Overriding the ToString() method
By default, the ToString() method removes the namespace from the agent's fully qualified name, as well as the "thinker", "aithinker" or "thinkerai" suffixes. However, this method can be overridden in order to behave differently. One such case is when agents are parameterizable, and differentiating between specific parametrizations during matches and sessions becomes important.

Included Agents
Three test agents are included with the framework, serving both as an example on how to implement an agent, as well as a baseline reference for testing other agents.
The sequential agent always plays in sequence, from the first to the last column and going back to the beginning, although skipping full columns. It will start by using round pieces, and when these are over it starts using square pieces. Therefore, it is not a "real" AI agent.
The random agent plays random valid moves, avoiding full columns and unavailable shapes. It can be parameterized with a seed to perform the same sequence of moves in subsequent matches (as long as the same valid moves are available from match to match).
The minimax agent uses a basic, unoptimized Minimax algorithm with a naive heuristic which privileges center board positions. It can be parameterized with a search depth, and, although simple, it is able to surprise unseasoned human players -even at low search depths.

Deployments
The ColorShapeLinks framework has been used to host two internal competitions (in separate semesters) in the AI for Games course unit at Lusófona University's Videogames BA, as well as an international AI competition in the IEEE CoG 2020 conference. These deployments are discussed in the next two subsections.

Internal Competitions in AI for Games Course Units
ColorShapeLinks was used as an assignment and internal competition in an AI for Games course unit during the two semesters of the 2019/20 academic year. In both semesters, the submitted AI agents and associated reports were graded preliminarily and separately from the final competition. Since students work in groups of 2 or 3 elements, an individual discussion was also performed. Results from the internal competition were used to potentially improve the preliminary grades, not lower them, since the main goal was to motivate students and have an engaging class where students watched and commented on the performance of each others agent's in real time. Nonetheless, if an agent was not competent enough to enter the competition, i.e., it freezed the Unity project or did not respond to cancellation requests, up to 1 point could be subtracted from the final grade. No students from the first semester repeated the course during the second semester.
However, there were several differences between the two semesters. In the first semester, ColorShapeLinks was a Unity-only assignment, as stated in Section 3.4. The minimum requirement for passing-i.e., to have a grade of 10 or higher (grades are given in a 0-20 scale)-was that students implemented an agent capable of defeating the sequential and random agents. The basic minimax agent, described in Section 4.5, was not included in the framework at this time. In the second semester, the console frontend and the basic minimax agent were added to the framework, with the assignment coinciding with the first few weeks of the international competition discussed in the next section. The minimum passing requirement in the second semester was for the submitted agent to beat the basic minimax implementation.
Grade distribution and summary statistics for the ColorShapeLinks assignment in both semesters are shown in Fig. 5 and Table 4, respectively.
Looking at the overall results in both semesters, at least 80% of the students had a passing grade (≥ 10) and participated actively in the assignment. Students less interested in the AI aspect of game design and development mostly submitted Minimax-based agents, e.g. with alpha-beta pruning, just to pass the project. They were, nonetheless,  generally more committed than in other AI and programming assignments. On the other end, students more comfortable with programming and AI generally dedicated more hours to the assignment and came up with interesting and competitive agents. Most, if not all students were highly engaged with the final live competition during class (e.g., "my AI is better than yours"!). There were, however, some notable grading differences between the two semesters. Grades in the second semester were higher in average, and more students met the passing grade (Table 4), even though the minimum requirement was higher. Grade distribution (Fig. 5) shows that, in the first semester, a considerable number of students aimed at the bare minimum just to get a passing grade, while in the second semester students generally went for more elaborate solutions. We argue there were three main reasons, which separately or in combination, led to this outcome: 1. The console app allowed some students to better test and debug their agent implementations, without being constrained by Unity. 2. A few students might have been motivated due to working on an assignment which was at the same time an international AI competition. 3. The minimax agent allowed students to study and better understand how a "real" agent could be implemented, allowing them to build upon it.
These results appear to show that ColorShapeLinks was successful in allowing students with various interests and with different capabilities within game making-as is the case of students in Lusófona's BA degree-to be able to produce palpable, working AI code, and to feel included when addressing this challenging topic.

IEEE CoG 2020 International Competition
ColorShapeLinks was accepted as an official AI competitions at the IEEE CoG 2020 conference, being awarded a prize money of 500 USD for the winner of each track. The competition ran on two distinct tracks: 1. The Base Track used standard Simplexity rules with a time limit of 0.2 seconds per move. Only one processor core was available for the AI agents. 2. The Unknown Track was played on a multi-core processor under a parameterization known only after the competition deadline, since it was dependent on the result of a public lottery draw.
The goal of the Base Track was to test agent capabilities in the standard Simplexity game. The Unknown Track evaluated the generalization power of the submitted solutions when applied to a most likely untested parameterization.
For each track, the submitted agents played against each other two times, so each had the opportunity of playing first. Agents were awarded 3 points per win, 1 point per draw and 0 points per loss, with the final standings for each track depending on the total number of points obtained per agent.
Classifications for the Base Track were updated daily during a five month period, up until the submission deadline, together with two larger test parameterizations. This allowed participants to have an idea of how their submission was faring, and update it accordingly.
The competition had a total of six submissions, four of which were from undergraduate students, both solo and in teams. Two of the submissions were students of the author which fared well in the internal competition discussed in the previous subsection. Although the number of submissions was low, the fact that four of them were from undergrads, partially demonstrated that the competition was accessible.
Eita Aoki, from Japan, won the Base Track with his Thunder agent, which used MCTS together with a custom bit board implementation. João Moreira, from Portugal (and a student of the author), won the Unknown Track with SureAI, a highly optimized Minimax-based agent. While interesting, none of these agents was truly state-of-the-art, leaving the door open for better agents going forward.

Conclusions
In this paper we presented ColorShapeLinks, and AI board game competition framework specially designed for game development students and educators, with openness and accessibility at its core. The arbitrarily-sized Simplexity board game-implemented by the framework-offers a good balance between simplicity and complexity, being approachable by undergraduates, while posing a non-trivial challenge to researchers and more advanced students. The framework has been successfully used for hosting internal competitions in a AI for Games course unit, as well as for hosting an international AI competition, validating its usefulness. 13