Authors: Andrew, George Gu, Jerry.
What is the problem?
we will make a program representing the chess-like board game Reversi. We will implement the board and all the rules of that game, and a player will be able to make different moves on the board. The rules of Reversi can be found in https://en.wikipedia.org/wiki/Reversi.
What is the something extra?
We will make a bot which a player can play against. It will make basic legal moves according to the rules when playing against the player.
What did we learn from doing this?
Starting new projects in Prolog happens very quickly as no classes or data structures are really need to be defined. Instead, only an idea of a data structure is required, and rules and predicates can be written based around this theoretical structure.
We used lists to implement a 8X8 chess board. We implement the board to be a list of 8 lists, and each list has 8 elements instead of a list of 64 elements. We think by breaking 64 elements into 8 lists is easier for us to consider the list as 8 rows and 8 columns. We can use traditional X, Y coordinates by referring to elements as the Xth element in the Yth list of the initial list. However, when we write the functions, we find it might be easier to just have a list of 64 elements because there is only 1 list that needs to be scan through.
We also discovered that Prolog can be much more intelligent than we anticipated. We have statements to see what pieces can be flipped when a move is made, but ensure that they do not search outside the bounds of the list. However with small scale tests, we found that unlike other languages, accessing elements out of bounds will not break Prolog programs, instead the statement will just return false continue. Bounds checking is not necessary at all.
in conclusion, we had lots of coding practice. The trace function is really helpful when we have problems as we can see all calculations that the program tried to do.