首页 > > 详细

159.272讲解、辅导Programming Paradigms、c/c++编程讲解、Python,Java语言辅导 讲解留学生Process

Computational Thinking
Page 1 of 3
159.272 Programming Paradigms
Assignment 2
Playing a board game: Reversi
Playing board games interactively is a common computational activity. We can use
abstraction to aide in the design of board games by separating the game logic from the actual
user interaction required to play the game. No matter the type of user interface provided to
play the game (text-based, desktop environment, web browser), the underlying logic remains
the same.
In this assignment, you will complete a Scala implementation of Reversi (also called Othello),
a game for two players, played on a board divided into 64 squares, arranged in 8 rows and 8
columns, with a set of 64 chips. Each chip has a dark and a light-colored side, with each
colour belonging to one of the two players. The players place their chips on the board and
flip the chips of their opponent, with the goal of having the most chips of their colour on the
board at the end of the game.
A chip can only be placed into a square that is adjacent to a chip of the opponent and that
forms at least one straight line of attack (horizontal, vertical, diagonal). A line of attack is
formed between two squares containing the players chips for which there are one or more of
the opponent's chips between the two. The opponent's chips within the line of attack are then
flipped.
Play alternates between the players until all the squares are filled or neither player can move.
If one player cannot move but the opponent can, play continues with the opponent. The
winner is the player with the most chips at the end of the game.
See Maths is Fun to have a practice, or read the wikiHow entry.
The Scala code for this assignment is contained in three files in the zip file
assignment2_2019.zip assignment2_2019.zip
Reversi.scala Reversi.scala
GameTree.scala GameTree.scala
Main.scala Main.scala
The game logic is contained in the file Reversi.scala Reversi.scala.
Your main task is to define the functions in Reversi.scala Reversi.scala using the provided data
types.Computational Thinking
Page 2 of 3
Instructions:
1. 1. Create a new Scala project in Eclipse.
2. Add the files Reversi.scala Reversi.scala, GameTree.scala GameTree.scala, Main.scala Main.scala to the src
folder of the project.
3. Complete the functions in Reversi.scala Reversi.scala. Replace the with your
definitions.
4. Main.scala Main.scala defines the main class of the application with the main method.
Run and test your changes in the the main method defined in Main.scala Main.scala.
The final function call in the main method starts the game. Right click and run the
main class as a Scala application as you did at the tutorials.
In lectures, we will explain the concepts behind the GameTree.scal GameTree.scala code. You
should work through the code and make an effort to understand how these concepts
have been implemented. The most important concern is to ensure that your functions
defined in Reversi.scal Reversi.scala return sensible values of the correct types, so that the
other modules can sensibly use your completed code.
Your second task considers the estimat estimate function in GameTree.scal GameTree.scala which takes
a Player value and a Game value and returns an integer value, which "rates" the
result of placing the given piece on the current board, for that player.
Your second task is to "make this function smarter". The vanilla version returns a score
for the given player and the given board, defined as the number of pieces currently
belonging to the player. Can you make this function smarter? This function can be
modified to account for strategic concerns, e.g. corners are worth more than edges,
which are worth more than other positions. The important point is that you can modify
this function without changing any of the other code, and end up with a smarter
program. Think about what you would need to do to alter this program behavior using
other programming paradigms.
When you have a finished version, submit your files Reversi.scal Reversi.scala and
GameTree.scal GameTree.scala for marking. You will get (up to) 12 marks for a correct working
version of Reversi.scala, modulated by the use of good functional programming
style, and (up to) 3 marks for an updated version of GameTree.scala, modulated
by the sophistication of your improvements .
Submit your work on Stream by 8pm (Beijing time) Tuesday 4th June. The deadline
encroaches on the Study break but this is so that we don’t clash with other courses
having deadlines early in Week 12.

联系我们
  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-21:00
  • 微信:codinghelp
热点标签

联系我们 - QQ: 99515681 微信:codinghelp
程序辅导网!