2nd Semester Programming Project Written Test

StrongerCantor avatar
StrongerCantor
·
·
Download

Start Quiz

Study Flashcards

10 Questions

Implement a tail-recursion method to determine if there is a consecutive sequence of n cells with the same value in a provided list of cells.

def nInLine(col: List[Cells.Cell], c: Cells.Cell, n: Int): Boolean = { }

Implement the 'winner' method to determine if either the computer or the player has won the game by having a continuous horizontal or vertical sequence of four units.

def winner(b: Board, player: Cells.Cell): Boolean = { }

Using foldRight or foldLeft, implement a method that takes the board and returns a list of indices corresponding to columns with empty cells.

def columnsWithEmptyCells(b: Board): List[Int] = { }

Complete the given code snippet in the 'Controller' class responsible for changing the text of 'label1' to 'You won!' if the player (playing with the Blue color) has won the game.

game.winner(Cells.Blue)

Briefly comment on the statement: 'It is appropriate to include the User Interface Pattern Fat Menu in the graphical interface of the Connect Four game.'

The Fat Menu pattern might not be suitable for the Connect Four game UI as it could introduce unnecessary complexity and clutter.

What is the purpose of the method 'nInLine'?

Determining if there is a consecutive sequence of n equal cells in a provided cell line.

What is the objective of the game 'Quatro em Linha' described in the content?

To create a continuous sequence of 4 units horizontally, vertically, or diagonally.

What does the 'transpose' method do in the context of the game implementation?

It transposes the matrix, converting rows into columns and columns into rows.

Complete the code snippet to change the text of 'label1' to 'You won!' when the player wins with the color blue: class Controller { @FXML var label1: Label = _ def onMouseClicked(): Unit = { if(game.winner(player) { label1.setText("___"); } } }

You won!

Provide a brief comment on whether it is appropriate to include the 'Fat Menu' User Interface Pattern in the graphical interface of the game 'Quatro em Linha'.

Answers may vary depending on the potential benefits or drawbacks of utilizing the 'Fat Menu' UI Pattern in the specific context of the game.

Study Notes

Programação Multiparadigma

  • The project is about developing a game called Quatro em Linha (human vs computer) on a 6x7 board using the following data types:
    • type Board = List[List[Cells.cell]]
    • object Cells extends Enumeration with type Cell = Value and val Red, Blue, Empty = Value

Game Rules

  • The game is played on a vertical board, where the player can only play in the free position of the highest index column.
  • The objective is to create a continuous sequence of 4 units horizontally, vertically, or diagonally.
  • The first player to create this sequence wins the game.

Class List API

  • apply(n: Int): A - gets the element at the specified index.
  • contains[A1 >: A](elem: A1): Boolean - tests whether the list contains a given value.
  • count(p: (A) => Boolean): Int - counts the number of elements in the collection that satisfy a predicate.
  • dropWhile(p: (A) => Boolean): List[A] - drops the longest prefix of elements that satisfy a predicate.
  • exists(p: (A) => Boolean): Boolean - tests whether a predicate holds for at least one element of the list.
  • filter(p: (A) => Boolean): List[A] - selects all elements of the list that satisfy a predicate.
  • find(p: (A) => Boolean): Option[A] - finds the first element of the list satisfying a predicate, if any.
  • foldLeft[B](z: B)(op: (B, A) => B): B - applies a binary operator to a start value and all elements of the sequence, going left to right.
  • foldRight[B](z: B)(op: (A, B) => B): B - applies a binary operator to all elements of the list and a start value, going right to left.
  • head: A - selects the first element of the iterable collection.
  • indexOf[B >: A](elem: B): Int - finds the index of the first occurrence of some value in the sequence.
  • indexWhere(p: (A) => Boolean, from: Int): Int - finds the index of the first element satisfying a predicate after or at some start index.
  • init: List[A] - returns the initial part of the collection without its last element.
  • isEmpty: Boolean - tests whether the list is empty.
  • last: A - selects the last element.
  • length: Int - returns the length (number of elements) of the list.
  • map[B](f: (A) => B): List[B] - builds a new list by applying a function to all elements of the list.
  • reverse: List[A] - returns a new list with elements in reversed order.
  • takeWhile(p: (A) => Boolean): List[A] - takes the longest prefix of elements that satisfy a predicate.
  • transpose[B](implicit asIterable: (A) => collection.Iterable[B]): List[List[B]] - transposes the iterable collection of iterable collections into a iterable collection of iterable collections.
  • updated[B >: A](index: Int, elem: B): List[B] - returns a copy of the list with one single replaced element.

Programação Multiparadigma

  • The project is about developing a game called Quatro em Linha (human vs computer) on a 6x7 board using the following data types:
    • type Board = List[List[Cells.cell]]
    • object Cells extends Enumeration with type Cell = Value and val Red, Blue, Empty = Value

Game Rules

  • The game is played on a vertical board, where the player can only play in the free position of the highest index column.
  • The objective is to create a continuous sequence of 4 units horizontally, vertically, or diagonally.
  • The first player to create this sequence wins the game.

Class List API

  • apply(n: Int): A - gets the element at the specified index.
  • contains[A1 >: A](elem: A1): Boolean - tests whether the list contains a given value.
  • count(p: (A) => Boolean): Int - counts the number of elements in the collection that satisfy a predicate.
  • dropWhile(p: (A) => Boolean): List[A] - drops the longest prefix of elements that satisfy a predicate.
  • exists(p: (A) => Boolean): Boolean - tests whether a predicate holds for at least one element of the list.
  • filter(p: (A) => Boolean): List[A] - selects all elements of the list that satisfy a predicate.
  • find(p: (A) => Boolean): Option[A] - finds the first element of the list satisfying a predicate, if any.
  • foldLeft[B](z: B)(op: (B, A) => B): B - applies a binary operator to a start value and all elements of the sequence, going left to right.
  • foldRight[B](z: B)(op: (A, B) => B): B - applies a binary operator to all elements of the list and a start value, going right to left.
  • head: A - selects the first element of the iterable collection.
  • indexOf[B >: A](elem: B): Int - finds the index of the first occurrence of some value in the sequence.
  • indexWhere(p: (A) => Boolean, from: Int): Int - finds the index of the first element satisfying a predicate after or at some start index.
  • init: List[A] - returns the initial part of the collection without its last element.
  • isEmpty: Boolean - tests whether the list is empty.
  • last: A - selects the last element.
  • length: Int - returns the length (number of elements) of the list.
  • map[B](f: (A) => B): List[B] - builds a new list by applying a function to all elements of the list.
  • reverse: List[A] - returns a new list with elements in reversed order.
  • takeWhile(p: (A) => Boolean): List[A] - takes the longest prefix of elements that satisfy a predicate.
  • transpose[B](implicit asIterable: (A) => collection.Iterable[B]): List[List[B]] - transposes the iterable collection of iterable collections into a iterable collection of iterable collections.
  • updated[B >: A](index: Int, elem: B): List[B] - returns a copy of the list with one single replaced element.

This is a 1 hour and 30 minutes written test for the 2nd semester programming project, with a total of 8 points. Students must answer questions on the respective pages and follow specific rules.

Make Your Own Quizzes and Flashcards

Convert your notes into interactive study material.

Get started for free

More Quizzes Like This

Use Quizgecko on...
Browser
Browser