正好我们老师也要做了这个作业!就来蹭个热闹~
大概就是实现了要求的功能,然后能够自定义棋盘大小(目前是6行7列,通过修改Connect4::play()里面的对于rowNum和colNum的赋值来实现自定义棋盘大小),能够选择先手后手,能够选择人机、人人模式;可能还有没有测试出来的的bug;可能代码不是很规范;
采用模式匹配的方式,给程序下棋提供一点参考(其实也就是预先设计了几种优先考虑的情况)
补上控制台输出样例:
Welcome to the game 'Connect 4' in console!
Chose the game mode:
- 1. PvC
- 2. PvP.
1
Game mode: Player v.s. Computer
Who goes first?
- 1. Player
- 2. Computer
1
Game starts!
中间省略若干行……
. . . . . . . . . @: Player
. . . . . . . . . $: Computer
@ . . . . . . . .
$ . @ . . @ . . .
$ @ @ @ $ @ . . .
@ $ $ $ @ $ $ @ $
-----------------
1 2 3 4 5 6 7 8 9
Round: 20
History: 1 2 2 3 3 4 5 6 4 1 3 5 6 7 8 9 6 1 1