LP102 2019 Spring

Homework 1

Abstract

Write a C [1] program that can play the games of Go and GoBan.

1 Introduction of Go and Goban

Go (called WeiQi in China) and Goban (called WuZiQi in China) are ancient

board games. The board is marked by horizontal and vertical lines. Stones,

white or black, will be placed on the intersections of lines. Two players will

use different colors of stone, and put their stones in turn on the board. Go

and Gomoku have different rules of winning. The rules of the two games are

simple. We can find online documents for their rules.

Rules of Go:

The picture above is from https://tromp.github.io/go/le…

1

https://en.wikipedia.org/wiki…

https://senseis.xmp.net/?Basi…

Rules of Goban:

https://en.wikipedia.org/wiki…

2 Gaming data storage

2.1 Board and stone

A 2–dimentional array of integers is used to record the stones on the board.

If the board has 19 × 19 lines, then we can use an 19 × 19 board. At a

line interscetion on the board, there are 3 possible stone occurrences there:

Empty, Black, White. We can use 3 different integers of represent the 3

stones, such as 0, 1, 2. Initially, the board is empty, which means each item

in the 2D arrary of the board is Empty. When a user pick a coordinate, say

E 6, to place a stone, say a black stone, if Black is represented as 1, then

the corresponding update of the board can be represented as the following

assignment statement:

board4 = 1

2.2 Game play history record

We can use a 3D integer array to record the history of a game, which is

a sequence the positions where stones are put during the game. We don’t

need to remember which position is black or white in the history, since we

assume a black stone is always put first. This history array will be saved to

a file on a hard drive, or be loaded from a hard drive to memory.

3 Display of gaming data

The board and stones can be printed using ASCII characters at the command

line. Here is some screen record of playing GNU Go:

White (O) has captured 0 pieces

Black (X) has captured 0 pieces

A B C D E F G H J K L M N O P Q R S T Last move: White C5

19 . . . . . . . . . . . . . . . . . . . 19

2

18 . . . . . . . . . . . . . . . . . . . 18

17 . . . . . . . . . . . . . . . . O . . 17

16 . . . + . . . . . + . . . . . O X . . 16

15 . . . . . . . . . . . . . . . . O . . 15

14 . . . . . . . . . . . . . . . X . . . 14

13 . . . . . . . . . . . . . . . . . . . 13

12 . . . . . . . . . . . . . . . . . . . 12

11 . . . . . . . . . . . . . . . . . . . 11

10 . . . + . . . . . + . . . . . X . . . 10

9 . . . . . . . . . . . . . . . . . . . 9

8 . . . . . . . . . . . . . . . . . . . 8

7 . . . . . . . . . . . . . . . . . . . 7

6 . . . . . . . . . . . . . . . . . . . 6

5 . .(O). . . . . . . . . . . . . . . . 5

4 . . . + . . . . . + . . . . . + . . . 4

3 . . . X . . . . . . . . . . . . . . . 3

2 . . . . . . . . . . . . . . . . . . . 2

1 . . . . . . . . . . . . . . . . . . . 1

A B C D E F G H J K L M N O P Q R S T

black(9): o2

White (O) has captured 0 pieces

Black (X) has captured 0 pieces

A B C D E F G H J K L M N O P Q R S T Last move: Black O2

19 . . . . . . . . . . . . . . . . . . . 19

18 . . . . . . . . . . . . . . . . . . . 18

17 . . . . . . . . . . . . . . . . O . . 17

16 . . . + . . . . . + . . . . . O X . . 16

15 . . . . . . . . . . . . . . . . O . . 15

14 . . . . . . . . . . . . . . . X . . . 14

13 . . . . . . . . . . . . . . . . . . . 13

12 . . . . . . . . . . . . . . . . . . . 12

11 . . . . . . . . . . . . . . . . . . . 11

10 . . . + . . . . . + . . . . . X . . . 10

9 . . . . . . . . . . . . . . . . . . . 9

8 . . . . . . . . . . . . . . . . . . . 8

7 . . . . . . . . . . . . . . . . . . . 7

6 . . . . . . . . . . . . . . . . . . . 6

3

5 . . O . . . . . . . . . . . . . . . . 5

4 . . . + . . . . . + . . . . . + . . . 4

3 . . . X . . . . . . . . . . . . . . . 3

2 . . . . . . . . . . . . .(X). . . . . 2

1 . . . . . . . . . . . . . . . . . . . 1

A B C D E F G H J K L M N O P Q R S T

GNU Go is thinking…

white(10): E4

Here is the screen shot of playing Goban using with another board design:

This the game setting:

board-size: 13; win-size: 5; lines-on-board: Yes

Enter to continue

!!!!!!! Welcome to Dragon Go !!!!!!

A B C D E F G H J K L M N

13 +—+—+—+—+—+—+—+—+—+—+—+—+ 13

| | | | | | | | | | | | |

12 +—+—+—+—+—+—+—+—+—+—+—+—+ 12

| | | | | | | | | | | | |

11 +—+—+—+—+—+—+—+—+—+—+—+—+ 11

| | | | | | | | | | | | |

10 +—+—+—+—+—+—+—+—+—+—+—+—+ 10

| | | | | | | | | | | | |

9 +—+—+—+—+—+—+—+—+—+—+—+—+ 9

| | | | | | | | | | | | |

8 +—+—+—+—+—+—+—+—+—+—+—+—+ 8

| | | | | | | | | | | | |

7 +—+—+—+—+—+—+—+—+—+—+—+—+ 7

| | | | | | | | | | | | |

6 +—+—+—+—+—+—+—+—+—+—+—+—+ 6

| | | | | | | | | | | | |

5 +—+—+—+—+—+—+—+—+—+—+—+—+ 5

| | | | | | | | | | | | |

4

4 +—+—+—+—+—+—+—+—+—+—+—+—+ 4

| | | | | | | | | | | | |

3 +—+—+—+—+—+—+—+—+—+—+—+—+ 3

| | | | | | | | | | | | |

2 +—+—+—+—+—+—+—+—+—+—+—+—+ 2

| | | | | | | | | | | | |

1 +—+—+—+—+—+—+—+—+—+—+—+—+ 1

## A B C D E F G H J K L M N

It is now move of BLACK

Please give the coordinates (a letter and a digit) to put your stone, according to the board:

d5

A B C D E F G H J K L M N

13 +—+—+—+—+—+—+—+—+—+—+—+—+ 13

| | | | | | | | | | | | |

12 +—+—+—+—+—+—+—+—+—+—+—+—+ 12

| | | | | | | | | | | | |

11 +—+—+—+—+—+—+—+—+—+—+—+—+ 11

| | | | | | | | | | | | |

10 +—+—+—+—+—+—+—+—+—+—+—+—+ 10

| | | | | | | | | | | | |

9 +—+—+—+—+—+—+—+—+—+—+—+—+ 9

| | | | | | | | | | | | |

8 +—+—+—+—+—+—+—+—+—+—+—+—+ 8

| | | | | | | | | | | | |

7 +—+—+—+—+—+—+—+—+—+—+—+—+ 7

| | | | | | | | | | | | |

6 +—+—+—+—+—+—+—+—+—+—+—+—+ 6

| | | | | | | | | | | | |

5 +—+—+—X—+—+—+—+—+—+—+—+—+ 5

| | | | | | | | | | | | |

4 +—+—+—+—+—+—+—+—+—+—+—+—+ 4

| | | | | | | | | | | | |

3 +—+—+—+—+—+—+—+—+—+—+—+—+ 3

| | | | | | | | | | | | |

2 +—+—+—+—+—+—+—+—+—+—+—+—+ 2

| | | | | | | | | | | | |

1 +—+—+—+—+—+—+—+—+—+—+—+—+ 1

A B C D E F G H J K L M N

## 5

1. Print the current game information: print the board, show the

stones on the board, indicate what is the last move, and whose

turn to play now.