| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 873 人关注过本帖
标题:一道玩井子游戏的题目...
只看楼主 加入收藏
winston37
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2010-11-3
结帖率:0
收藏
已结贴  问题点数:0 回复次数:9 
一道玩井子游戏的题目...
Since the Tic-Tac-Toe board is like a 3×3 grid we will consider this board to have 9
positions as demonstrated by the following diagram.
|---|---|---|
| 1 | 2 | 3 |
|---|---|---|
| 4 | 5 | 6 |
|---|---|---|
| 7 | 8 | 9 |
|---|---|---|
Each player in turn places their symbol (an O or an X) on one of the 9 positions. The
game ends when one of the players places three O's or X's in a line
(horizontal/vertical/diagonal) OR when all positions have been filled.
Whoever completes the first line wins, if no line has been completed and all positions
have been filled then we have a draw.
SPECIFICATIONS:
Here are some details on what you have to do.
1. You should begin by outputting some Welcome message, welcoming players into
your game.
2. Then your program should output the initial Tic-Tac-Toe board (see Sample Input
and Output section for details) then ask Player X (since Player X starts) to choose
a position (from 1 through to 9) to place an X. Player X’s choice for position must
be verified as he/she may enter anything from a standard keyboard. Also a player
must always choose from one of the remaining positions.
3. Once we have a valid choice for a position from a player we put his/her symbol
(i.e. an X or an O) in that position.
4. Then your program should verify whether or not there will be a next round by first
checking if all positions have been filled. If all 9 positions have been filled then
this will be the final round.
5. Another situation where we may not have a next round is if one of the players
have won already. Therefore that’ll be your next move, i.e. to determine if we
have 3 X’s (or O’s) in a line (horizontal/vertical/diagonal). If we do have a winner
then make sure that you record it so that you can announce it later.
6. If there will be a next round then first switch to the other player (i.e. if current
player is Player X then next player will be Player O and vice versa) and repeat
from step 2.
7. If no more rounds left then either declare the winner OR say that we have a draw
(all 9 positions have been filled but no lines of three X’s or O’s
SAMPLE INPUT and OUTPUT
Each of the following cases demonstrates the input and output of one run of my program.
I have highlighted the inputs from the user.
Case 1:
**************************************************
--------------------------------------------------
WELCOME TO MY TIC-TAC-TOE
--------------------------------------------------
**************************************************
Tic-Tac-Toe board:
|---|---|---|
| 1 | 2 | 3 |
|---|---|---|
| 4 | 5 | 6 |
|---|---|---|
| 7 | 8 | 9 |
|---|---|---|
PLAYER X, Its your turn!
Choose one of the remaining positions? 12
Incorrect input. Must enter one of the INTEGERS BETWEEN 1 and 9.
Choose one of the remaining positions? a45
Incorrect input. Must enter one of the INTEGERS BETWEEN 1 and 9.
Choose one of the remaining positions? -4
Incorrect input. Must enter one of the INTEGERS BETWEEN 1 and 9.
Choose one of the remaining positions? @#
Incorrect input. Must enter one of the INTEGERS BETWEEN 1 and 9.
Choose one of the remaining positions? 1
Tic-Tac-Toe board:
|---|---|---|
| X | 2 | 3 |
|---|---|---|
| 4 | 5 | 6 |
|---|---|---|
| 7 | 8 | 9 |
|---|---|---|
PLAYER O, Its your turn!
Choose one of the remaining positions? 1
Position taken. Must enter one of the REMAINING POSITIONS.
Choose one of the remaining positions? 8
Tic-Tac-Toe board:
|---|---|---|
| X | 2 | 3 |
|---|---|---|
| 4 | 5 | 6 |
|---|---|---|
| 7 | O | 9 |
|---|---|---|
PLAYER X, Its your turn!
Choose one of the remaining positions? 2
Tic-Tac-Toe board:
|---|---|---|
| X | X | 3 |
|---|---|---|
| 4 | 5 | 6 |
|---|---|---|
| 7 | O | 9 |
|---|---|---|
PLAYER O, Its your turn!
Choose one of the remaining positions? 3
Tic-Tac-Toe board:
|---|---|---|
| X | X | O |
|---|---|---|
| 4 | 5 | 6 |
|---|---|---|
| 7 | O | 9 |
|---|---|---|
PLAYER X, Its your turn!
Choose one of the remaining positions? 4
Tic-Tac-Toe board:
|---|---|---|
| X | X | O |
|---|---|---|
| X | 5 | 6 |
|---|---|---|
| 7 | O | 9 |
|---|---|---|
PLAYER O, Its your turn!
Choose one of the remaining positions? 7
Tic-Tac-Toe board:
|---|---|---|
| X | X | O |
|---|---|---|
| X | 5 | 6 |
|---|---|---|
| O | O | 9 |
|---|---|---|
PLAYER X, Its your turn!
Choose one of the remaining positions? 9
Tic-Tac-Toe board:
|---|---|---|
| X | X | O |
|---|---|---|
| X | 5 | 6 |
|---|---|---|
| O | O | X |
|---|---|---|
PLAYER O, Its your turn!
Choose one of the remaining positions? 5
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
FINAL Tic-Tac-Toe board:
---|---|---|
X | X | O |
X | O | 6 |
O | O | X |
---|---|---|
:) Winner is PLAYER O
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Case 2:
**************************************************
--------------------------------------------------
WELCOME TO MY TIC-TAC-TOE
--------------------------------------------------
**************************************************
Tic-Tac-Toe board:
|---|---|---|
| 1 | 2 | 3 |
|---|---|---|
| 4 | 5 | 6 |
|---|---|---|
| 7 | 8 | 9 |
|---|---|---|
PLAYER X, Its your turn!
Choose one of the remaining positions? 5
Tic-Tac-Toe board:
|---|---|---|
| 1 | 2 | 3 |
|---|---|---|
| 4 | X | 6 |
|---|---|---|
| 7 | 8 | 9 |
|---|---|---|
PLAYER O, Its your turn!
Choose one of the remaining positions? 7
Tic-Tac-Toe board:
|---|---|---|
| 1 | 2 | 3 |
|---|---|---|
| 4 | X | 6 |
|---|---|---|
| O | 8 | 9 |
|---|---|---|
PLAYER X, Its your turn!
Choose one of the remaining positions? 1
Tic-Tac-Toe board:
|---|---|---|
| X | 2 | 3 |
|---|---|---|
| 4 | X | 6 |
|---|---|---|
| O | 8 | 9 |
|---|---|---|
PLAYER O, Its your turn!
Choose one of the remaining positions? 9
Tic-Tac-Toe board:
|---|---|---|
| X | 2 | 3 |
|---|---|---|
| 4 | X | 6 |
|---|---|---|
| O | 8 | O |
|---|---|---|
PLAYER X, Its your turn!
Choose one of the remaining positions? 8
Tic-Tac-Toe board:
|---|---|---|
| X | 2 | 3 |
|---|---|---|
| 4 | X | 6 |
|---|---|---|
| O | X | O |
|---|---|---|
PLAYER O, Its your turn!
Choose one of the remaining positions? 2
Tic-Tac-Toe board:
|---|---|---|
| X | O | 3 |
|---|---|---|
| 4 | X | 6 |
|---|---|---|
| O | X | O |
|---|---|---|
PLAYER X, Its your turn!
Choose one of the remaining positions? 6
Tic-Tac-Toe board:
|---|---|---|
| X | O | 3 |
|---|---|---|
| 4 | X | X |
|---|---|---|
| O | X | O |
|---|---|---|
PLAYER O, Its your turn!
Choose one of the remaining positions? 4
Tic-Tac-Toe board:
|---|---|---|
| X | O | 3 |
|---|---|---|
| O | X | X |
|---|---|---|
| O | X | O |
|---|---|---|
PLAYER X, Its your turn!
Choose one of the remaining positions? 3
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
FINAL Tic-Tac-Toe board:
---|---|---|
X | O | X |
O | X | X |
O | X | O |
---|---|---|
:( BORING DRAW
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
搜索更多相关主题的帖子: 游戏 
2010-11-03 09:16
yangfanconan
Rank: 7Rank: 7Rank: 7
等 级:贵宾
威 望:10
帖 子:397
专家分:541
注 册:2009-9-22
收藏
得分:10 
很好很强大。
2010-11-03 09:20
winston37
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2010-11-3
收藏
得分:0 
haha
2010-11-03 09:22
winston37
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2010-11-3
收藏
得分:0 
回复 楼主 winston37
haha
2010-11-03 09:23
winston37
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2010-11-3
收藏
得分:0 
回复 2楼 yangfanconan
2010-11-03 09:39
帝国
Rank: 3Rank: 3
来 自:云南昆明
等 级:论坛游侠
帖 子:68
专家分:144
注 册:2010-10-11
收藏
得分:10 
基本没看懂,好像看图说话,麻烦翻译一下,另外把代码弄上来,写好注释哦。
2010-11-03 10:26
heitao
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2010-11-19
收藏
得分:0 
头都达拉

[url=www./]安徽网站优化[/url][url=www./]机动车[/url]
2010-11-19 09:36
orgthing
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2010-12-28
收藏
得分:0 
有难度啊

http://
http://
2010-12-28 22:53
JacobsChan
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2011-2-11
收藏
得分:0 
楼主FIC的?
2011-02-19 14:05
风卷浪起
Rank: 3Rank: 3
来 自:universe
等 级:论坛游侠
威 望:4
帖 子:190
专家分:149
注 册:2021-11-13
收藏
得分:0 
牛啊!

人生苦短,我用Python~~~
对Pygame相关内容有兴趣,求带。
2021-11-17 21:38
快速回复:一道玩井子游戏的题目...
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.030213 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved