编程CS计算机科学案例代码:加农炮游戏Forsyth–Edwards Notation
当前位置:以往案例 > >编程CS计算机科学案例代码:加农炮游戏Forsyth–Edwards Notation
2018-04-30

Your task consists of three parts:

Server: The game server manages the gameplay and connection to the WebFrontend. Its main task is to check for correctness and to calculate and deliver the new game state. Your task is the concrete implementation of Cannon's rules within the given game server template. The implementation is object-oriented in Java.

Quality assurance: In order to ensure a correct course of the game, the functionality of the server that you have implemented should be tested extensively with the help of jUnit. In addition, the code quality should be measured and ensured by means of certain metrics.

Bot: Since in addition to the game against a human challenger, the game against computer opponents to be possible, you develop a bot in Haskell. The bot should compute all possible traits for a given correct game state and choose one. In the end it should be possible to compete against each other and to organize a tournament of your implementations.

加农炮游戏规则

http://boardspace.net/cannon/english/Cannon.htm (英文版)

http://boardspace.net/english/about_cannon.html 游戏模拟器

Notation

FEN-Notation https://en.wikipedia.org/wiki/Forsyth%E2%80%93Edwards_Notation

blob.png

The game board is described by a FEN string

b- lack soldier

B –  black city

w – white soldier

W – white soldier

n ∈ [1, 9] n empty fields

/ – Next row

First the field a9 is given, finally the field j0. The information is in rows.

Empty rows also remain empty in the FEN string. The game board at the beginning will be like follows:

/1w1w1w1w1w/1w1w1w1w1w/1w1w1w1w1w///b1b1b1b1b1/b1b1b1b1b1/b1b1b1b1b1/

或者

/1w1w1w1w1w/1w1w1w1w1w/1w1w1w1w1w/1111111111/1234/b1b1b1b1b1/b1b1b1b1b1/b1b1b1b1b1/

Game status

To describe the game state, the description of the board to show which player is currently at the turn. At the beginning (white starts) is:

/1w1w1w1w1w/1w1w1w1w1w/1w1w1w1w1w///b1b1b1b1b1/b1b1b1b1b1/b1b1b1b1b1/

After placing the cities as in the example, the game board would look like this:

4W5/1w1w1w1w1w/1w1w1w1w1w/1w1w1w1w1w///b1b1b1b1b1/b1b1b1b1b1/b1b1b1b1b1/7B2

Canon

士兵可以组成一个加农炮火车(如何组成见规则),描述方式为从起始士兵到尾部士兵,如a1-b2

开火

When firing with a cannon, 声明尾部的士兵和要开火的地点 (for example, 输入a1-a5, if there is a canon on a1, a2, a3, and an enemy soldier on a5).

移动

When moving a cannon, 声明要移动的士兵和要移动到的地点(eg, a1-a4, if there is a canon on a1, a2, a3 and a4 is free).

放置城市 可以用如下方式声明

The placement of a city is by a train with the same start and

Target coordination indicated (so for example d0-d0, if black site is at the beginning of his

City placed on d0). 黑方执子时,d0-d0就是声明黑方把城市放在了d0的位置上。

blob.png

Game server for Cannon in Java

Most of the game server has already been implemented. In addition, the GUI and communication is already there. The task now is to develop a data model in the already started class CannonGame for the concrete game Cannon, with which the state of the game can be described. This is to implement the function tryMove (format of a move, see Cannon notation), which checks if a move is valid and executes it if possible. In addition, two functions have to be implemented with which a game state (board with FEN string, see section Cannon notation) can be transferred or called up. Normally, a new CannonGame must start with the start state (see Cannon rules). All code that you have inserted will be tested automatically with jUnit tests. Branch coverage (at bytecode level) should be achieved. However, the test object is the specification, that is, if functional content is missing, the test cases are also not complete. The test trap must pass successfully. After implementing the functionality and the test trap, you may need to apply suitable refactorings. The code you are developing must meet the following metrics:

metrics

maximum value

Rows per function (Method Lines of Code)

25

McCabe Cyclomatic Complexity

20

Nesting depth (nested block depth)

4

Number of parameters per function

5

Guideline

By guideline, we have put together an Eclipse Servlet project in which all client functionality (HTML files with Javascript) and the servlet are already included. There is also a README file in the project that contains some information for orientation. In the existing classes, TODO comments mark the places where you should continue (functionality is missing in the class CannonGame). New classes must be in the package de.tuberlin.sese. swtpp.gameserver.model.cannon.

Existing code may not be changed (except if it is exlizit there). For the test trap we have defined a special format. A sample test case can be found in the class TryMoveTest (here are also your test cases out.) There are three functions available for the test trap:

l The function startGame ensures that the game is started, for easier testing with any score (figure assignment on the board in the FEN string) and the selection of who should be in line.

l The assertMove function passes a move and the executing player to the game, and checks to see if the result matches your expected result (tryMove returns true if the move was valid and performed).

l The assertGameState function checks whether the overall game state (current board (FEN), next player, game finished or not, who won) covers with what you surrender as expectation.

In your test cases, only these functions can be used. Each test case can contain any number of calls to all functions. Each test case must end with a call to assertGameState. Test cases must be tested successfully, otherwise they will not be included in the test coverage measurement.

Cannon Bot in Haskell

Haskell编译一个cannon游戏的机器人。机器人需要能计算出所有可能的路线并从中选出一条。只需要编译功能不需要考虑美观。附件有一份编译的的框架

l 模块(module)的名称(也就是CannonBot)不可以更改,

l 另外一些已经导入的模块 Util和Data.char 不可以导入其他模块。Util函数的声明和定义也不可更改。getMove和listMoves函数的功能和名字也不可更改(用于审核这个作业)。

l 作业的内容就是将getMove he listMoves 补全,完善机器人的功能。两个函数都收到被编译成String的游戏目前情况(见notation)。你可以假设你只能得到有效的字符创来实际编译可能的游戏情况。

listMoves函数应该算出一个在这种情况下所有可能的移动步骤并按照notation的方式输出string。只有在各种测试游戏情况下给出所有符合规则的游戏步骤,才会得分。

getMove函数在所有选出的移动步骤中选出一个,并返回他。选择的规则可以根据自己的策略。

附件的模块中附有一个测试文件,用于测试输出的内容是否符合格式标准。请注意一定要输出正确格式的内容,否则无法将无法用于测试。打开Fotmat-module,然后运行main函数即可运行test。前提是已经正确的安装了HUnithttps://github.com/hspec/HUnit)。最终只需要上传CannonNot.hs文件即可。

提示

In the guideline, a simple persistence is built in, which saves created data and reloads it upon restart. This should make manual testing easier for you. New classes should implement the java.io.Serializable interface. The location of the database file can be customized in the GameServerServlet file.

If you want to try out the bot (见作业三) with your Java implementation, you can hook it up using the HaskellBot class. To do this, you need to compile the bot into a executable file (see Main.hs) and place the path where it can be found in the GameFactory class.

The Code coverage checked us with the plugin Emma in Eclipse. If all your Code is displayed in Emma green (100% Branch Coverage), Code coverage is complete. The  Code coverageis assessed without the units already covered by the test cases in the template. In addition, we will test with our own tests of the same format, if the functionality is fully implemented. In the absence of functionality, test cases are also missing.

The guideline contains an example test. This is of the same format as our test cases. So if he does not go through it, then basically something may not be right with your implementation, e.g. your parser of the FEN string.

The project is to be submitted as an exported eclipse project in .zip format.

Also name the project to contain the group name. Development and execution environment:

n JDK 8

n Eclipse in J2EE-Version

n Tomcat 8 http://tomcat.apache.org/download-80.cgi

n It may be that the project does not run in every browser. Firefox should go, Javascript should be activated

To visualize playing fields you can use the GUI test page. You will find her

with the server started under

http://127.0.0.1:8080/GameServer/Cannon_Board.html.

The game board could be passed as a JavaScript parameter for example:

http://127.0.0.1:8080/GameServer/Cannon_Board.html?4W5/1w1w1w1w1w/1w1w1w3w/1w3www1w//7w2/b1bb2bbb1/b1b3b1b1/b1b1b3bb/2B7

blob.png



在线提交订单