联系方式

  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-21:00
  • 微信:codinghelp

您当前位置:首页 >> Python编程Python编程

日期:2020-12-06 06:37

project-10

Remember that this project cannot be submitted late.

Write a class called BuildersGame that represents the board for a two-player game that is

played on a 5x5 grid. During the game, each players' builders will move around the board

and add levels to towers. The winner is the first one to move a builder on top of a 3-story

tower.

Learn Git and GitHub without any code!

Using the Hello World guide, you’ll start a branch, write comments, and open a pull

request.

Read the guide

Star Watch

master

timalcon … 1 minute ago

12/3/2020 osu-cs161-f20/project-10-jinchuantian: project-10-jinchuantian created by GitHub Classroom

https://github.com/osu-cs161-f20/project-10-jinchuantian 2/3

First, x places her two builders on the board, then o places her two builders on the board.

Throughout the game, no two builders can ever occupy the same square. After the initial

placements are complete, x must move either one of her builders to an adjacent square

(one square orthogonally or diagonally). Builders always move to the top of the tower on

their destination square. Builders can move any number of levels down, but can move at

most 1 level up (they can also stay at the same level). You can visualize it as the builders

hopping from the top of one tower to the top of another, but they can never move to a

tower that is more than one level higher than the tower they're on. After a builder moves, it

must add a level to an adjacent square (it must be adjacent to the builder that moved). A

level cannot be added to a square that is occupied by any builder. Once a tower has a 4th

level, no further levels can be added. After x has moved and built, the players alternate

moving and building in this way until the game ends. If a player moves one of her builders

on top of a 3-story tower or if her opponent will not have a legal move available, then she

has won.

The class should have the following private data members - a representation of the board;

the current state, which holds one of the three following values: "X_WON", "O_WON", or

"UNFINISHED"; and something to keep track of whose turn it is.

It should have an init method that initializes the board to being empty, initializes the

current_state to "UNFINISHED", and appropriately initializes any other data members.

Tip: Probably the easiest way of representing the board is to use a list of lists. The init

method could then initialize the board to a list of 5 lists, each of which contains 5 empty

strings (or whatever character you want to use to represent an empty space).

It should have a get method named get_current_state, which returns the current state.

It should have a method named initial_placement that takes five parameters: the row and

column of each of the player's two builders, and either 'x' or 'o' to indicate the player who is

placing builders. Rows and columns will be integers in the range 0-4. For example,

initial_placement(0,1,4,2,'o') would place o's builders at row 0, column 1 and row 4, column

2. If one of the chosen squares is already occupied, initial_placement should return False.

Also, if the player placing builders doesn't match the player whose turn it is, or if this

method is called for a player that has already made a valid initial placement, then it should

return False. Otherwise, it should update the board, update whose turn it is, and return True.

12/3/2020 osu-cs161-f20/project-10-jinchuantian: project-10-jinchuantian created by GitHub Classroom

https://github.com/osu-cs161-f20/project-10-jinchuantian 3/3

It should have a method named make_move that takes six parameters: the row and column

of the piece to move, the row and column of the square it's moving to, and the row and

column of where to build. For example, make_move(2,0,3,1,3,0) would move the builder at

row 2, column 0 to row 3, column 1 and then build a level at row 3, column 0. If the game

has already been won or drawn, or if the move is invalid, make_move should return False.

Also, if the builder being moved doesn't belong to the player whose turn it is, or if this

method is called before both players have made their initial placements, then it should

return False. Otherwise, it should record the move, update the current state, update whose

turn it is, and return True. To update the current state, you need to detect if this move put a

builder on top of a 3-story tower, or if the opponent will not have a legal move available.

It's not required, but you'll probably find it useful for testing and debugging to have a

method that prints out the board.

Whether you think of the list indices as being [row][column] or [column][row] doesn't matter

as long as you're consistent.

As a very simple example, your class could be used as follows:

game = BuildersGame()

game.initial_placement(2,2,1,2,'x')

game.initial_placement(0,1,4,2,'o')

game.make_move(2,2,1,1,1,0)

game.make_move(0,1,1,0,2,0)

game.get_current_state()

Your file must be named: BuildersGame.py

Releases

No releases published

Create a new release

Packages

No packages published

Publish your first package


版权所有:编程辅导网 2021 All Rights Reserved 联系方式:QQ:99515681 微信:codinghelp 电子信箱:99515681@qq.com
免责声明:本站部分内容从网络整理而来,只供参考!如有版权问题可联系本站删除。 站长地图

python代写
微信客服:codinghelp