国外学校的一道计算机题,大家给看看,英文的

勿为 2014-03-07 07:42:22
我同事的儿子在国外读书遇到的一道难题,要3月8日早上5点之前完成:
For this problem, the classes you write must be implemented using the class keyword.
In this problem you will write a C++ program to administer the game of Tic-Tac-Toe
(http://en.wikipedia.org/wiki/Tic-Tac-Toe), which involves two players, X and O. Play-
ers take turns claiming squares on a 3x3 grid, until one player has claimed a straight line of
three squares (that player wins the game) or until the grid is full (and no one wins). Your
program will play several rounds of this game and report the winner. A sample interaction
follows (your input is in italics):
game stdin stdin
X's move
NW
O's move
C
X's move
SW
O's move
N
X's move
W
X wins
Score is
X 1
O 0
quit
In between games, two commands are recognized:
game sX sO Starts a game. sX denotes the name of the le from which X's moves will
be taken. stdin indicates that the moves will come from cin, i.e., X's moves will be
interactive. Similarly for O.
quit Ends the program
Within a game, players take turns claiming squares. The nine squares are arranged as follows:
NW N NE
W C E
SW S SE
When a player's moves come from stdin, it is considered invalid input to claim a square that
has already been taken. On the other hand, when the moves come from a le, it is hard to
know in advance what squares will have been taken. Thus, when the moves come from a le,
a player's move is dened to be the next square in the le that is not already claimed. Note
that it would be redundant for a square to occur more than once in the le, and therefore we
consider any le that contains a square more than once to constitute invalid input.
A sample interaction where both players' moves come from les is presented below. Suppose
that movesX.txt contains the following:
NW SE NE C E N S W SW
Suppose that movesO.txt contains the following:
C SE SW E N NW NE S W
Then the interaction would be as follows:
game movesX.txt movesO.txt
X's move
(plays NW)
O's move
(plays C)
X's move
(plays SE)
O's move
(plays SW)
X's move
(plays NE)
O's move
(plays E)
X's move
(plays N)
X wins
Score is
X 1
O 0
quit
Note, in particular, that when the moves come from a le, your program prints to stdout the
move that was made (e.g., (plays NW) above).
You may assume that if a player's moves are taken from a le, then the le will contain
enough moves to complete the game.
Within a game, play alternates between X and O. X plays rst in odd-numbered games
(starting from 1), and O plays rst in even-numbered games.
A win is worth one point. A loss is worth no points. If a game is drawn (no one wins), then
no points are awarded for that game. In the case of a draw, print Draw to stdout, instead of
X wins or O wins.
To structure this game, you must include at least the following classes:
ScoreBoard which tracks the number of games won by each player and the current
state of the board. This class must be responsible for all output to the screen, except
X's move and O's move (these will be printed by code in the Player class, described
below).
Player which encapsulates a game player, and keeps track of the source from which a
player is receiving input.
You must use the singleton pattern to ensure that there is only one scoreboard in the game.
In addition, you must generalize the singleton pattern to ensure that only two Player objects
can be constructed.
Each Player object must possess a pointer to this scoreboard, and these pointers will be
intialized in the way prescribed by the singleton pattern. Each player object must be re-
sponsible for registering its move with the scoreboard by calling a ScoreBoard::makeMove
method. This method should take parameters indicating which player is calling the method,
and the amount to be deducted from the total. If necessary, a player object may query the
board by calling a method ScoreBoard::isOccupied to nd out whether a given position is
taken. This method would only be called if the player object's input comes from a le, for
the purpose of determining the next unoccupied position in the le.
Your main program will be responsible for keeping track of which player's turn it is. It will
call a method in ScoreBoard to start a game, whenever the user enters a game command. In
addition, it will alternately call a method on the two player objects that will cause the player
to get the next move from its input source and then pass that move on to the scoreboard.
The chain of method calls is therefore roughly the following:
main program, in response to a game command from the user, calls a method ScoreBoard::startGame
to initiate a game.
main program calls a method for each of the two player objects, to pass to them their
respective input streams
main program alternately calls Player::makeMove for player objects A and B. This
method should take no parameters.
The Player::makeMove method will be responsible for fetching the next move and calling
the ScoreBoard::makeMove method to register the move with the scoreboard.
Your solution must use const declarations for variables, members, and parameters whenever
possible.
Your solution must not leak memory.
You may assume that all input is valid.
Due on Due Date 1: Design a test suite for this program (call the suite le suiteq4.txt
and zip the suite into a3q4a.zip).
Due on Due Date 2: Full implementation in C++. Your mainline code should be in
le a3q4b.cc, and your entire submission should be zipped into a3q4b.zip and submitted.
Your zip le should contain, at minimum, the les a3q4b.cc, scoreboard.h, scoreboard.cc,
player.h, and player.cc. If you choose to write additional classes, they must each reside
in their own .h and .cc les as well.
...全文
357 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
勿为 2014-03-11
  • 打赏
  • 举报
回复
楼上说的不错,有一个星期的时间做四道题,这个是第四题,同事的儿子连续整了三十几个小时没整出来,同事担心儿子再做下去,身份体会受不了,所以叫我看看出出主意。由于还剩6个多小时交题,我水平有限,肯定也做不出来,而且也没LINUX调试环境,所以才放上来让大家看看有没有接触过。前几天听说他们大多数都没做出这道题,老师又给了一个星期的时间。说实说话这题是没啥难度,但需要时间。
勤奋的小游侠 2014-03-11
  • 打赏
  • 举报
回复
是读本科?不是说外国的教育是培养孩子独立吗?做父母的就让他自己搞呗,要是父母真的这么有钱,就花钱买代码吧。
petermaomao 2014-03-11
  • 打赏
  • 举报
回复
不就是圈叉棋么?这么水出国干啥!
FancyMouse 2014-03-08
  • 打赏
  • 举报
回复
这种project一般至少能给你一个礼拜的时间做。 题意的限制大部分都只是把架构给你定下来,你自己套代码就是了。这都能叫限制的话我不知道进公司写代码是不是要摔碗。 而且目测愿意看这么长描述的人都没几个,更不用说写代码了。我觉得lz还是实际一点,叫你那同事儿子出点钱找个人写掉它。不想出钱那就给他自己一个教训,以后别due date前一天才开始折腾project。
勿为 2014-03-07
  • 打赏
  • 举报
回复
有两种输入方式,一种是通过键盘两人轮流输入,另一种是通过X、O的两个步骤文件进行输入,来判断谁赢。 关键是这道题对编程过程有很要求或叫作限制。
zxvivian 2014-03-07
  • 打赏
  • 举报
回复
NW N NE W C E SW S SE 按照这个格式写一个三子棋?程序包含两个类ScoreBoard和Player
勿为 2014-03-07
  • 打赏
  • 举报
回复
关键是这题目的要求太多了,必须按它的要求来写
xudero 2014-03-07
  • 打赏
  • 举报
回复
《C语言入门经典》上有Tic-Tac-Toe的实现,不过是C语言版本的,可以参考下改造成类
unituniverse2 2014-03-07
  • 打赏
  • 举报
回复
现在出国的人都这么水吗?
taodm 2014-03-07
  • 打赏
  • 举报
回复
夷语的不看,看不懂。

64,439

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧