Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
pp:2023:scala:l06 [2023/04/07 17:19]
alexandra.udrescu01
pp:2023:scala:l06 [2023/04/08 07:49] (current)
pdmatei
Line 3: Line 3:
 ==== 5-Tic-Tac-Toe ==== ==== 5-Tic-Tac-Toe ====
  
-**Tic Tac Toe** is usually played on a 3x3 board, marking positions by each player in rounds. Our game is slightly different:+**Tic Tac Toe** is usually played on a 3x3 board, marking positions by each player in rounds. Our game is slightly different ​(usually called 5-in-a-row):
   * it can be played on a square board of any size **larger or equal to 5**.   * it can be played on a square board of any size **larger or equal to 5**.
   * A player wins if it has marked a line, column or diagonal of **5 consecutive positions** in a row.    * A player wins if it has marked a line, column or diagonal of **5 consecutive positions** in a row. 
Line 31: Line 31:
   * In your project template, ''​X''​ is encoded as the **first** player (''​One''​),​ and ''​0'',​ as ''​Two''​.   * In your project template, ''​X''​ is encoded as the **first** player (''​One''​),​ and ''​0'',​ as ''​Two''​.
 <code scala> <code scala>
-trait Player {} 
 trait Player {} trait Player {}
 case object One extends Player { case object One extends Player {
Line 97: Line 96:
 **6.1.7.** Implement the following functions for extracting diagonals above/below the first/​second diagonal, as lines. It's not really necessary to make sure that at least 5 positions are available, for now. Hint: if one function must be implemented with element-by-element iteration, the three other can be implemented using each-other, as single-line calls. **6.1.7.** Implement the following functions for extracting diagonals above/below the first/​second diagonal, as lines. It's not really necessary to make sure that at least 5 positions are available, for now. Hint: if one function must be implemented with element-by-element iteration, the three other can be implemented using each-other, as single-line calls.
 <code scala> <code scala>
-def getAboveFstDiag(b: Board): List[Line] = ??? +def getAboveFstDiag:​ List[Line] = ??? 
-def getBelowFstDiag(b: Board): List[Line] = ??? +def getBelowFstDiag:​ List[Line] = ??? 
-def getAboveSndDiag(b: Board): List[Line] = ??? +def getAboveSndDiag:​ List[Line] = ??? 
-def getBelowSndDiag(b: Board): List[Line] = ???+def getBelowSndDiag:​ List[Line] = ???
 </​code>​ </​code>​
  
 **6.1.8.** Write a function which checks if a player is the winner. Hint: functions ''​l.forall(_)''​ and ''​l.exists(_)''​ may be very helpful, together with patterns. **6.1.8.** Write a function which checks if a player is the winner. Hint: functions ''​l.forall(_)''​ and ''​l.exists(_)''​ may be very helpful, together with patterns.
 <code scala> <code scala>
-def winner(p: Player): Boolean = +def winner(p: Player): Boolean = ???
 </​code>​ </​code>​