====== 2. Reversi game ======
Rules: https://en.wikipedia.org/wiki/Reversi
{{:courses:be5b33kui:labs:reversi:reversi-game.png|}}
===== Task =====
Your task is to download the ZIP file and alter the downloaded ''player.py'' file for the Reversi game and then play a Reversi tournament against the players of the rest of the class.
===== Learning outcomes =====
This task will teach you about:
* Adversarial search
* Combinatorial explosion
* Search algorithm effectivity
The solution can be generalized to other classical games, although in some cases this strategy does not lead to optimal solutions and you would use different approaches (e.g.: [[https://en.wikipedia.org/wiki/Computer_Go|Go]]).
===== Supporting Codes =====
You can find the codes in the student repository [[https://gitlab.fel.cvut.cz/kui-student-materials/kui-reversi|KUI Reversi]]:
- Create a working directory on your disk, e.g., ''kui-reversi''.
- You can get the codes into it in two ways:
* Using ''git'': Clone the kui-reversi repository:
cd kui-reversi
git clone https://gitlab.fel.cvut.cz/kui-student-materials/kui-reversi.git .
Don't forget the ''.'' at the end of the previous example: the dot tells ''git'' to clone the contents of the repository into the current working directory.
* Using a ZIP archive:
- Download the codes from the [[https://gitlab.fel.cvut.cz/kui-student-materials/kui-reversi|KUI Reversi]] repository as a ZIP file (or directly download [[https://gitlab.fel.cvut.cz/kui-student-materials/kui-reversi/-/archive/master/kui-reversi-master.zip|kui-reversi-master.zip]]).
- Inside the downloaded archive, you will find the folder ''kui-reversi-master''. Extract its contents into the ''kui-reversi'' folder. (You should not see a subdirectory ''kui-reversi-master'' inside the ''kui-reversi'' folder.)
In the supporting codes, you will find:
* ''player.py'' - a module with a template for your player, and also
* graphical (''reversi_creator.py'') and terminal (''headless_reversi_creator.py'') environments allowing you to run and play the game.
===== Player specification =====
The file ''player.py'' contains the ''MyPlayer'' class with a few methods. You can use the method that is already implemented in the ''MPlayer'' class called ''get_all_valid_moves'' in order to get all the valid moves and thus focus only on your strategy and decision how to play the game.
* The code must be **Python 3** compatible, otherwise it can fail during automatic evaluation!
^ method ^ input ^ output ^explanation ^
| ''%%__%%init%%__%%'' | ''my_color'', ''opponent_color'', ''board_size'' | ''None'' | Creates a player and its opponent. The board size is in the constructor - you can use it for any heuristics calculation. |
| ''get_all_valid_moves'' | ''board''| list of coordinate tuples | Method returns for a given board all the valid moves.|
| ''select_move'' | ''board'' (n x n game board) | r , c (row, column) a tuple - coordinates of your move | The input is 2D ''list'' - current game board. Method should return a valid move. Example: (0,0) means putting your stone to the position ''board[r][c]''. If no valid move is possible return ''None''. ''board'' values -1 for empty space and 0/1 for the stone color. The max time spent within the ''move'' method is 5 secs. **This is the method you are supposed to alter.**|
===== MyPlayer properties =====
* The **docstring** should be informative enough and **short** (80 characters at most).
* Attribute **name** should contain the **username of the student**.
Example of MyPlayer implementation
class MyPlayer:
'''super-smart indeed'''
def __init__(self, my_color,opponent_color):
self.name = 'username' #username of the student
def select_move(self,board):
return (0, 0)
===== Evaluation =====
** Late submissions do not take part in the tournament and receive 0 points. **
Points are given in the following way:
- The player must work and generate correct moves (e.g.: not outside the board).
- Manual evaluation is done by the teachers with regards to your code quality.
- The automatic evaluation gives points based on automatic code testing and the rank of the player in the tournament.
^ Evaluation ^ min ^ max ^ note ^
| Algorithm quality | 0 | 1 | Evaluated based on automatic evaluation whether the player follows the Reversi game rules. |
| Code quality | 0 | 4| Comments, code structure, cleanliness, proper naming... We will take the complexity of the algorithm used into account as well - e.g. minimax with alpha-beta pruning vs. heuristics as a look-up table only.|
| Rank in the tournament | 0 | 6 | The tournament truly pits your code against your classmates'. Based on the ranking in the tournament, we distinguish for each sub-tournament (based on the board size) five levels and give them their respected point count: 1-2-3-4-6. Your final score is the maximum of the points gained in the subtournaments. If your player does not finish the tournament because of its mistake, you get 0 points. |
===== Submission =====
Upload a ZIP archive with the module ''player.py'' and any other possible modules you created to the [[https://cw.felk.cvut.cz/upload/|Upload system]]. **All the files must be in the archive's root folder! The archive cannot contain any other folders!**
Information about the tournament:
* you play against all the other players on boards of the size $n\times n$, $n \in \{6,8,10\}$ in three separate subtournaments
* every match consists of two games - first, player "A" starts, then player "B" starts
* there are 2 points for winning the match, 1 for a draw, 0 for losing both games
* 5 seconds limit per move - try it out in Brute
* illegal moves results in losing a game
* exceeding the time limit means losing the game
* creating the player (constructor) takes at most 60s
* don't use multithreading
===== Results =====
TBA