Java代写:CS150 Chutes and Ladders

Introduction

继续上次代写的Snakes and ladders,新增几个功能。

Your second project is to modify and extend your game from project 1. Bear in mind that the game will be extended again in project 3 so design your game and the implementation to be “easily” modified and extended.

Project Description

Changes to the existing game (Project 1):

  1. extend the game by adding a third dimension. The length of each of the 3 dimensions can be different.
  2. each player now has j tokens on the board. For each turn, a player has a single roll of the dice and can only move one of the tokens.
  3. random numbers are now generated with a uniform distribution and the percentage frequencies in the configuration file can be changed after every run.
  4. priorityHold is now implemented with a TreeMap and not a Priority Queue.
  5. the format of the configuration file has been changed (see section on the configuration file).
  6. Hold, HoldQ and PriorityHold have been modified to prevent getting “stuck”.

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 one 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 token 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, 0) and there are no aids, obstacles or treasures at that location.
  6. There are no aids on the last row of the board.
  7. The score of each player is calculated with the following formula:
    (a) Finishing the game (i.e., arriving at the last spot on the board) is worth w points
    (b) Each treasure piece is worth v points
    The winner is the player with the highest total number of points from all the tokens that they control.

Board Components

The following components (data structures) have been modified/added from Project 1:

  • (modified) PriorityHold - the token is added to the container (TreeMap) 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.
  • (new) JStack - the token is moved up/down by a number of floors (z-coordinate) modulo the length of the third dimension, i.e., it wraps around. The direction is determined by a factor which can be either +1 or −1. The number of floors is determined by the dice roll. The factor is determined randomly when the space/tile is created.
  • (modified) Hold, HoldQ, PriorityQ: To exit the obstacle, the player/token must roll the same number they used to land on the obstacle (unchanged). However, they get an additional roll to determine where they land (multiplied by the factor).

Program Behavior

The program behaves as specified in the description for project 1.

Program Inputs

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

  • n - the maximum value returned by the dice (must be greater than 1)
  • k - the number of players (must be greater than 1)
  • j - the number of tokens per player (must be greater than 0)
  • 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:

  • board xyz the length of each of the 3 dimensions of the board
  • values wv the values of finishing and the value of each treasure piece
  • treasurePotA [percentage frequency] [number to remove] [nuomber 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]
  • JStack [percentage frequency]

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.

Errata

The aim of this project is to provide each player with a simple, limited “AI” as a player. You will probably have to provide additional functionality so that the AI can make an “intelligent” move. For example, if a move can result in landing on an obstacle/aid, the AI will want to know additional information such as the number of tokens already in a PriorityHold and their priorities. You should try to implement at least 4 different strategies.

Simplifications

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

  1. only implement some of the data structures, but you must have at least HoldQ and JStack
  2. limit the size of the board to have a maximum of 12x12x2
  3. limit the maximum number of players to 3 but each player has to have at least two tokens,
  4. have 2 game playing strategies.

Report

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

  1. What game playing strategy works best? (You will need to develop some strategies - some of them can be quite “stupid”) Is there a different strategy for:
    (a) finishing first,
    (b) being the first team to finish,
    (c) amassing the maximum amount of pieces,
    (d) amassing the maximum amount of points,
  2. what are the effects of changing:
    (a) the frequencies of the various aids and obstacles
    (b) the minimum and maximum factors of the holds