首页 > 其他分享 >CSCI1120 Introduction to Computing

CSCI1120 Introduction to Computing

时间:2024-11-26 19:24:00浏览次数:8  
标签:Computing Introduction Mathable player game Player CSCI1120 class board

CSCI1120 Introduction to Computing Using C++, Fall 2024/25

Assignment 6: Mathable Using OOP

Due: 23:59, Sat 7 Dec 2024                                                                                                          Full marks: 100

Introduction

The objective of this assignment is to practice the use of inheritance and polymorphism. Usage of strings, vectors and pointers is also included. You will implement the Mathable board game again but using an OOP approach this time.

In Assignment 4, we used static arrays and separate functions to implement the  board game with two variant settings, namely classical Mathable and Mathable Junior, which differ in board size, rack size and number of tokens. In this assignment, you are to reimplement the board game in an OOP style by developing several classes that model the game components.

For simplicity,

•   Only the Junior variant of the game is required. Its configuration is recapped in Table 1 below.

•   You may assume the board size, rack size, and total number of tokens are fixed (in Mathable.h).

•   No need to implement the “swap tokens” functionality – i.e., the option 'S' for the player’s action does not exist this time.

Table 1: Game configuration parameters of Mathable Junior

 

However, there are some new features to support:

•   The number of players can be varied between 2 and 4 at the program start.

•   Besides human players, we also implement computer players that make moves automatically.

•   The new game has to support two special types of squares in the original Mathable. Recall that

Restriction  squares are  those   blue  squares   (in  Figure  1  GUI)  marked  with   an  addition, subtraction, multiplication or division sign. To occupy a square of this kind, the player must make an equation that corresponds to the sign of that square.

One of the original game rules reads 代写 CSCI1120 Introduction to Computing “If a player places a token on a restriction square, he may, at that moment, take an extra token (from the bag) if he so wishes. This may not be postponed to a later turn.” To make it simple, we won’t implement this rule.

Bonus squares are those  marked with “2x”  or “3x” . A  purple square marked 2x doubles the amount of point of the token on that square; an orange square marked 3x triples the number of points.

Game Board Representation

The gameboard is represented by a text-based grid as shown in Figure 1 below.

 

Figure 1: A GUI screenshot of the Mathable app versus our text-based game board representation

Program Specification

This section describes the starter code, class  hierarchy,  player actions, game-over conditions, the TODO classes that require your major work, and the program flow.

Starter Code

•    To help you get started, you are provided with all the required source files. There is a total of  17 files implementing this program – 8 classes (header and source files) plus the main client source.

•    Your task is to fill in your code for the missing  parts marked with TODO comments in only 8 of  these files. The last column of the Table 2 and 3 indicates whether the file has some TODO task(s) for you. Search the word “TODO:” to locate where you should fill in the missing code. Read the  instructions in the TODO comment to know what is expected to do. You may remove the TODO  comments after finishing the missing code.

Table 2: Header files for class definitions

 

File

Description

TODO

1

Square.h

Square interface

A base class modeling a square on board

N

2

BonusSquare.h

BonusSquare interface

A subclass modeling a bonus square

Y

3

RestrictionSquare.h

RestrictionSquare interface

A subclass modeling a restriction square

N

4

Player.h

Player interface

An abstract base class modeling a player

N

5

Bot.h

Bot interface

A subclass modeling a computer player

N

6

Man.h

Man interface

A subclass modeling a human player

N

7

Mathable.h

Mathable interface

A class modeling game board and bag

N

8

RandomNumberGenerator.h

RandomNumberGenerator interface

A custom random number generator

N

Note: The constants P = 4, N = 10, R = 5, and = 60 are defined in Mathable.h, which correspond to maximum # players, board size, rack size, bag size (total # tokens) respectively.

Table 3: Source files for class implementations and client code

 

File

Description

Relation with other classes

TODO

9

Square.cpp

Square implementation

Base class

N

10

BonusSquare.cpp

BonusSquare implementation

Subclass of Square

Y

11

RestrictionSquare.cpp

RestrictionSquare implementation

Subclass of Square

Y

12

Player.cpp

Player implementation

Abstract base class

Y

13

Bot.cpp

Bot implementation

Subclass of Player

Y

14

Man.cpp

Man implementation

Subclass of Player

Y

15

Mathable.cpp

Mathable implementation

Player subclasses access board or bag via this object

Y

16

RandomNumberGenerator.cpp

RandomNumberGenerator implementation

Mathable’s setupBag() uses it for shuffling tokens

N

17

math-game.cpp

Mathable game client program

The main() function here

Y

•    We suggest the following development order.

o  The subclasses of Square: RestrictionSquare and BonusSquare;

o  Next is the Mathable class;

o  Then finish the base classes first: Player;

o  Followed by subclasses of Player: Bot and Man;

o  Finally, the game client program: math-game.cpp.

Class Hierarchy

 

Figure 2: The class inheritance hierarchies and relationship between classes

The Mathable class has a 2-D array of Square pointers, namely board[N][N], which implements the game board. BonusSquare and RestrictionSquare are subclasses of Square. They override the virtual function toString() to return more specific information like “3x” or “+” . The Player class  keeps a  pointer,  namely  mGame,  which  points  to  a  Mathable object. Then  methods  in the Player class or its subclasses can make moves, i.e., placing tokens on the game board, by calling the  methods  provided  by  Mathable.  Note  that  the  Player class  is  abstract  since  it  has  a  pure virtual  method  called  makeMove().  You  cannot  create  objects  of  this  class.  Man and  Bot are concrete  subclasses  of  the   Player class   modeling   a   human   player   and   a   computer   player respectively. They reuse the parent-level data such as score and rack as well as methods such as getScore() and rackSize(). They override their parent’s virtual makeMove() method to exhibit different behaviors in making moves – a human player enters a move via the keyboard whereas a computer player picks the move that obtains the highest points from all possible moves.

Besides the classes, we also define a type alias of int called Token in Square.hand we tend to use this alias for the type of variables storing a token. For example, a player’s rack is implemented as a vector storing the tokens, instead of writing vector rack, we would write vector rack, which looks more readable.

Human Player Actions:

There are 3 options of game actions that a human player (Man) can choose in each turn:

1. Play (P): play a move, i.e., select a token on the rack to place at a specified cell on the board.

2. End (E): end the current turn (if the player can’t see any more moves to make).

3. Terminate (T):  terminate  the  game   (prematurely).  Then   players’   current  total  scores   are compared to see who wins the game.

You may refer to Assignment 4 specification for their description.

Computer Player Actions:

A computer player (Bot) has no options for actions. It keeps playing all playable moves in a greedy manner, i.e., pick a combination of a token on its rack and a square on the board that can maximize the points gained by the current move, until there are no more possible moves. Then it passes the turn to the next player.

Game-over Conditions:

In this assignment, there are three game-over conditions:

(1)   There are no tokens left in the bag and one player has used up all tokens on his rack.

(2)    Every player has passed their turn to the next since they have no more possible moves.

•   Note: This situation can happen even if the bag is not empty (since the swap-tokens function is not supported in this assignment).

•   Hint: The possibleMoves() method provided by the Mathable class, to be discussed, can facilitate the detection of this situation.

(3)   A human player enters option T to terminate the game. (This allows us to end a game earlier as we wish, making program testing more flexible.)

Like Assignment 4, a draw game can happen if more than one players attain the same highest score.

 

标签:Computing,Introduction,Mathable,player,game,Player,CSCI1120,class,board
From: https://www.cnblogs.com/CSE231/p/18570814

相关文章

  • ISSCC2025 Computing-In-Memory Session 趋势整理
    今天下午ISSCC2025发布会开完,CIMSession花落谁家终于清楚了。今年CIM被放到了Session14,共录取七篇,投稿数如果和去年差不多的话,那么录取率应该是进一步下降了(去年录取了九篇)。只能说体感上来说就明显越来越卷。还是先来看一下录取的Paper:7篇都来自远东,两篇台湾,五篇大陆,东南......
  • CSC1005: Introduction to Computer Engineering
    CSC1005:IntroductiontoComputerEngineeringProgrammingandApplicationsAssignment3Assignmentdescription:Thisassignmentwillbeworth9%ofthefinalgrade.Youshouldwriteyourcodeforeachquestionina.pyfile(pleasenameitusingthequest......
  • INFS3208 – Cloud Computing Programming
    SchoolofInformationTechnologyandElectricalEngineeringINFS3208–CloudComputingProgrammingAssignmentTaskIII(10Marks)Taskdescription:Inthisassignment,youareaskedtowriteapieceofSparkcodetocountoccurrencesofverbsintheUN......
  • EMATM0061: Statistical Computing and Empirical
    Assignment 2EMATM0061:Statistical Computingand Empirical Methods,TB1, 2024IntroductionCreatean R MarkdownforassignmentFirst,itisrecommendedthatyou createa single R Markdown document to include   yoursolutions,withheadings ......
  • CS 417/517: Introduction to Human Computer Interaction
    CS417/517:IntroductiontoHumanComputerInteraction Project1(Fall2024)1IntroductionInthisassignment,yourtaskistoimplementaConvolutionalNeuralNetwork(CNN)andevaluatetsperformanceinclassifyinghandwrittendigits.Aftercompleti......
  • Introduction to the YouTube to WAV Conversion Website
    Title:IntroductiontotheYouTubetoWAVConversionWebsite-www.youtubetowav.topIntoday'sdigitalage,whereweconsumeavastamountofmultimediacontent,havingtheabilitytoconvertvideosintodifferentformatscanbeextremelyuseful.One......
  • FIT9132 Introduction to Databases
    FIT9132 Introductionto DatabasesAssignment 1 Logical- ReadMoreCommunity Library(RCL)PurposeGiventhe providedcasestudyfromAssignment 1-Conceptual,and additionalforms/documents relatedtothecasestudy,studentswillbeasked t......
  • Introduction to data Science with Python
    FINALASSESEMENT.IntroductiontodataSciencewithPythonGeneralInstructionsThisisthefinalassessmentforthecourse.Youneedtodownloadthedatasetsprovidedtoanswerthequestions.The5datasetsnamed'World_Happiness_Report'(there......
  • IBM AI Developer 专业证书专项课程-Introduction to Software Engineering-Unit2-前
    前端网站开发前端开发简介用户交互:用户在浏览在线购物网站时,主要与网站的前端进行交互。这包括浏览不同的页面、选择不同的产品类别、比较产品等活动。前端的作用:前端是用户直接接触的部分,它决定了用户如何与网站或应用进行交互,以及他们的视觉体验。网站开发基础HTML(Hyp......
  • FIT1047 Introduction to computer systems, networks and security
    FIT1047 Introductiontocomputersystems, networksand security-S2 2024Assignment2– Processesand MARIE ProgrammingPurposeProcessesandprogramsarewhatmakescomputers do what we want them to do. Inthefirst partofthisassig......