Homework 4 consists in developing a complete five-in-a-row game, together with an AI and a very basic interface.
For this part, you need to implement a function sequences
, that returns a map of the form: (5,a), (4,b), (3,c), (2,d)
where:
a
is the number sequences of length 5 that the player has established (on lines, columns or diagonals).b
is the number of sequences of length 4 which can be filled-out in order to achieve a 5-sequence. For example: XX XX
is such a sequence for player One
, however XX0XX
is not, since this cannot be filled-out in order to achieve a 5-sequence.c
(resp. d
) is the number of sequences of length 3 (resp. 2) which can be filled-out in order to achieve a 5-sequence.sequences
in a later stage of the project.winner
with a call to this function, to make the code more compact and avoid partial re-implementations.def sequences(p: Player)(b: Board): Map[Int,Int] = ???
For this part, you need to implement a functional project which consists of a running loop:
More details will be available during lecture.
For this particular part, tests are not necessary.
This part is at the very core of the project, and essentially consists of a function play
, which implements the AIs decision of selecting a move.
def play(p: Player, b: Board): Board = ???
You may slightly change the signature of this function, to accommodate your project.
You may start with a very basic (trivial) implementation, which will allow you to move on with 4.2. and then refine it after B.2. is complete.
We offer no guidelines about how this function should be implemented, this is entirely up to you, but you may consider:
Possible strategies:
play
by simply evaluating the sequences that are available in the current play, as well as those of the opponent. This local strategy may become complicated, require a lot of code, as the game may unfold in different ways. It is also important to have a good strategy for starting the game (e.g. a play in either corner of the board is a bad way to start).During the last lecture, we will play a tournament of Five-in-a-row, in which all your AI programs will compete.
The author the best AI implementations will be awarded a bonus of 0.2p.
The winner of the tournament will receive a maximal grade of 10 for the entire lecture (no attendance to the exam will be necessary).