ColorShapeLinks
An assignment for the AI course unit of the Bachelor in Videogames at Lusófona University
|
An assignment for the Artificial Intelligence course unit of the Bachelor in Videogames at Universidade Lusófona de Humanidades e Tecnologias, Lisbon, Portugal.
The goal of this assignment is to implement a competitive AI for the board game included in this repository, the rules of which are similar to the Simplexity board game. However, this board game can played with arbitrary number of rows and columns, as well as accepting different number of pieces in a row for achieving victory. For the purpose of this assignment, we will refer to this board game as ColorShapeLinks.
A Unity project implementing ColorShapeLinks is included in this assignment. The project should be executed within the Unity editor, not as a standalone build. Project execution can be configured by manipulating the SessionConfiguration
game object in the Unity Editor. This is done by: 1) editing the fields of the SessionController
script; and, 2) adding or removing AI scripts, i.e., scripts which extend AIPlayer
section.
SessionController
game objectFields of the SessionController
script are divided in three sections:
Tournaments occur automatically if there are more than two AI scripts active in the SessionConfiguration
game object. Otherwise a single match is played, as discussed in the next section.
Zero or more AI scripts can be added to the SessionConfiguration
game object. These scripts extend the AIPlayer
class, as discussed in the AI implementation section. The number of active AI scripts in the SessionConfiguration
game object determines what type of session will run:
During and after the tournament session, all match results as well as current standings / classifications, are presented.
This project has two tasks, namely, 1) the implementation of a competitive AI for the ColorShapeLinks board game, and, 2) writing of a report. These tasks are discussed in further detail in the next sections.
Students should implement a minimum of two classes. For example, if your AI is called G03VerySmart, these classes are as follows:
G03VerySmartAI
**, which extends AIPlayer
. This class should be added as a component of the SessionConfiguration
game object, and allows the AI to be found by the game and optionally configured in the Unity editor.G03VerySmartAIThinker
**, which implements the IThinker
interface. This is where the AI should actually be implemented.These classes should be in their own folder, G03VerySmart
, which in turn should be placed at Assets/Scripts/AI/AIs/
. This folder contains some examples of dumb AIs to demonstrate how the code should be organized.
Students should not modify existing code. If a bug is found in the included Unity project, a fix should be submitted through a pull request, so it becomes available to everyone.
AIPlayer
This class allows an AI to be found by the game, and for the AI to be optionally configured in the Unity editor. For that purpose, it must be added as a component of the SessionConfiguration
game object, and implement the following read-only properties:
PlayerName
, which should return the string with the AI's name.Thinker
, which should return an instance of the class that implements IThinker
.The instance of the class that implements IThinker
should be created in the Setup()
method, which needs to be overridden when extending AIPlayer
. The example AIs demonstrate how this should be done.
For configuring the AI in the Unity editor, the class that extends AIPlayer
can have editable fields (e.g. maximum search depth). Following best practices, these fields should be private and have the [[SerializeField
]] attribute.
For AIs that really want to search as long and deep as possible, the time limit is available in the AITimeLimit
property, and can be passed to the thinker during its instantiation in the Setup()
method.
IThinker
This class is where the AI should be implemented. The IThinker
interface defines the Think()
method, which accepts the game board and a cancellation token, returning a FutureMove
. Simply put, the method accepts the game board, the AI decides the best move to perform, and returns that move, which will eventually be executed by the game engine.
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, as exemplified in the following code:
The Think()
method is called in a separate thread from the main Unity thread. As such, most Unity classes and objects cannot be used by the thinker, especially those used in Unity's game loop, e.g. Time
and Random
. The Mathf
functions can be used without problems, since they do not depend on anything other than the input they are given.
Timing and random number generation functionality, useful or even mandatory for the thinker, can be obtained with native C# types such as DateTime
, TimeSpan
and Random
.
The thinker can freely modify the game board, since this is a copy and not the original game board being used in the main Unity thread. More specifically, the thinker can try moves with the DoMove()
method, and cancel them with the UndoMove()
method. The board keeps track of the move history, so the thinker can perform any sequence of moves, and roll them back afterwards.
The CheckWinner()
method 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 public read-only variable winCorridors
might be important. This variable is a collection containing all corridors (sequences of positions) where promising or winning piece sequences may exist.
The report should be in the form of a properly formatted Markdown file named README.md
, and contain the following information:
The assignment will be evaluated with a grade from 0 to 20, according to the following criteria:
Within these criteria, the following items will also be considered:
All AIs will face each other in two tournaments:
The bonuses and penalties are cumulative, but the final grade cannot be lower than 0 or higher than 20.
The assignment should be submitted by groups of 2 or 3 students, via Moodle, before January 7, 23:00, and must include the following items:
AIPlayer
IThinker
README.md
file.A discussion will be performed on January 8, during class, as well as the two tournaments referred in the previous section.
Academic dishonesty is unacceptable and will not be tolerated. Cheating, forgery, plagiarism and collusion in dishonest acts undermine the University's educational mission and the students' personal and intellectual growth. Lusófona students are expected to bear individual responsibility for their work, to learn the rules and definitions that underlie the practice of academic integrity, and to uphold its ideals. Ignorance of the rules is not an acceptable excuse for disobeying them. Any student who attempts to compromise or devalue the academic process will be sanctioned according to Lusófona regulations.
Text adapted from Baruch College.
This assignment (the text and non-code files) are made available under the Mozilla Public License 2.0. The code is made available under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
[[SerializeField
]]:https://docs.unity3d.com/ScriptReference/SerializeField.html