Java代写:CS150 Snakes and Ladders

Introduction

这次需要代写的是一个小时候玩过的棋盘类游戏,来自印度的蛇与梯子
从给定的文件中读取棋盘中蛇和梯子的信息,然后按照游戏规则编写即可。

Your first project is to build a game that is very similar to chutes and ladders - for the original version called “snakes and ladders” (see https://en.wikipedia.org/wiki/Snakes_and_Ladders). Bear in mind that the game will be extended in projects 2 and 3 so design your game and the implementation to be “easily” modified and extended.

Project Description

The initial game is composed of the following components:

  1. a 2 dimensional square board of size m by m with 0 based numbering, i.e, the first row has index 0 and the first column has index 0,
  2. a single dice which generates random numbers between 1 and n inclusive,
  3. k players represented by a token on the board,
  4. a configuration file which describes the types of ladders (aids) and chutes (obstacles) and treasure pieces. The aids, obstacles and treasure pots will be placed on the board using a Gaussian distribution.
    To see how to generate random numbers with a Gaussian (normal) distribution see http://www.javapractices.com/topic/TopicAction.do?Id=62.

Rules of the Game

The rules of the game are fairly straightforward and are:

  1. Each turn of the game consists of each player rolling the dice and moving their token the number of steps (from the dice) forward where possible.
  2. If the token lands on an aid or obstacle as the last step, then they will be affected by that aid or obstacle. Otherwise they are not affected by any aids or obstacles on the way.
  3. If the token lands on a treasure pot, the first person to land there will acquire a number of treasure pieces in that pot. The pot is non-renewable.
  4. The game ends when a player lands on the last spot in the board exactly. If a player rolls a number that takes them beyond the board, they will not be able to move their token for that turn.
  5. The players (tokens) start at location (0, 0) and there are no aids, obstacles or treasures at that location.

Board Components

The following components (data structures) will be utilized:

  • treasurePotA - a basic counter (counts down). Each time a token lands on that spot, it gains a fixed number of pieces and the counter is decremented by one. When the count reaches zero, no more pieces will be given out.
  • treasurePotB - an accumulator. Each time a token lands on that spot, it gains a number of pieces (specified by the dice roll). The pot is decremented by that number of pieces and when the count goes to zero, no more pieces will be given out.
  • Hold - the token is added to the container (ArrayList) with the value of the dice roll. Leaves the container if they roll that same value of the dice and advance by that number of steps multiplied by a factor.
  • PriorityHold - the token is added to the container (PriorityQueue) with a priority (value of the dice roll). They can leave the container if they are at the head of the queue on that turn. They then advance by that number of steps multiplied by a factor.
  • HoldQ - the token is added to the container (LinkedList with Queue operations) with the value of the dice roll. Leaves the container if (1) they are at the front of the queue and (2) they roll that same value of the dice to advance by that number of steps multiplied by a factor.

Program Behavior

The program behaves iteratively and at (i) the beginning of the game and (ii) the beginning of every subse- quent iteration, will prompt the user to select a command:

  • p - print a map of the board - location of every token, aid, obstacle and treasure pot and its status
  • c - move forward one turn
  • i - continue until the game ends, i.e., do not prompt at the next (or subsequent turns)
  • r - print status of each player/token; the position on the board and the number of treasure pieces in their possession

At the beginning, i.e., iteration 1 before any player has moved, the program will print a map of the board. At the end of the game, the progam will the status of each player/token. After each player’s move, the program will print the value, of the roll and results of the move (what has changed). If nothing has changed, print “No change” - e.g., if a player is in a Hold and does not roll the required value to exit the Hold.

Program Inputs

The following inputs will be through the args[] array in main() in the following order.

  • m - the length of each dimension of the board (must be greater than 1)
  • n - the maximum value returned by the dice (must be greater than 1)
  • k - the number of players (must be greater than 1)
  • the name of the config file

The configuration file will have specify the components in this incarnation of the program and will have the following content. Each line can be one of:

treasurePotA <percentage frequency> <number to remove> <number of removals>
treasurePotB <percentage frequency> <initial total>
Hold <percentage frequency> <min value of factor> <max value of factor>
PriorityHold <percentage frequency> <min value of factor> <max value of factor>
HoldQ <percentage frequency> <min value of factor> <max value of factor>

An example config file can be found on moodle.

Project Constraints

The following constraints apply to the project:

  1. The project is to be completed individually. The only person you can consult is the instructor.
  2. Each configuration of parameters should be run at least 5 times with different random seeds to obtain an “average” value.

Simplifications

You can simplify your project in one (or more) of the following ways:

  1. only implement some of the data structures, but at least one of them must be a Hold, PriorityHold or HoldQ,
  2. limit the size of the board to have a maximum of 10x10,
  3. limit the maximum number of players to 3.

Report

Your simulation and report should try to answer questions (you should design your own questions) like the
following:

  1. Suppose we want to ensure that the game will finish take 50 to 100 turns to complete for a given board size, what combination of parameters would satisfy this? How does this change as the board changes size?
  2. What is the computational complexity of the game based on:
    (a) the size of the board
    (b) the number of players
  3. Suppose the object of the game was to amass the maximum amount of treasure pieces. Does the first person to finish the game usually have the maximum number of pieces? What is the likelihood of the first person to finish having the maximum number of pieces?