Home>
Environment:

macOS Catalina version 10.15.1
Xcode Version 11.2.1

I'm trying to make a simple Go program with PlayGround in Xcode.

If i run the following code

.........
.........
.........
..... @ ...
... @. oo ..
.........
.... o ....
.........
.........


Will be output as follows.

While the game progresses as shown in the comments (1) to (5) of the code, it is only necessary to append "Start" to "Game", but return your hand once as shown in Comment (6). (5) disappears at this stage, and (1) (2) (3) (4) (7) I will.

I'd like to keep this in (1) ~ (5) and remember the change chart of (7) without erasing it.

That is,

(1)->(2)->(3)->(4)->(5)
                  L>(7)


I want to keep the state like in some way.

Please tell me what algorithm is used in such cases.

Thank you.

let Black: String = "@"
let White: String = "o"
let Empty: String = "."
let Board size: Int = 9
var number: String = black
struct start {
    var Color: String
    var x: Int
    var y: Int
    init (Color: String, x: Int, y: Int) {
        self.color = color
        self.x = x
        self.y = y
    }
}
var game record: [Start] = []
var aspect: [[String]] = Array (repeating: Array (repeating: empty, count: board size), count: board size)
func start (x: Int, y: Int) {
    Append (Start (color: turn, x: x-1, y: y-1))
    Play = hand == black? White: black
}
func return () {
    let Last start: Start = Gospel.popLast ()!
    Phase [Last Start. Y] [Last Start. X] = Empty
    Play = hand == black? White: black
}
Start (x: 6, y: 4) // (1)
Start (x: 5, y: 7) // (2)
Start (x: 4, y: 5) // (3)
Start (x: 7, y: 5) // (4)Start (x: 7, y: 4) // (5)
Return () // (6)
Start (x: 6, y: 5) // (7)
for i in 0 ..<棋 曲 .count {
    Phase [棋 [i] .y] [棋 [i] .x] = [[i] .color
}
for y in 0 ..<board size {
    for x in 0 ..<board size {
        print (phase [y] [x],

 separator: "", terminator: "")
    }
    print ()
}
Additional thought, based on masatoUchida's answer (2019.11.22 19:47)

I thought so.
So, I tried to express "How many hands" and "Branch number" in a simple way (How many hands, Branch number).

The first line from the initial state is the 0th line.
Here is the first line, returning to (2, 0), hitting another hand in the third hand and hitting the fifth hand.
In the second row, we went back to (1, 0) and hit another second and hit the fifth.
And here is the main topic.

If i go back to (3, 0) and hit the fourth move different from (4, 0), I think it will be expressed as (4, 3). Once you do so.
Now, let's say that if we go back to (3, 1) and hit the fourth move different from (4, 1), we will represent (4, 4).
Then, it looks good at first glance, but if you look at this figure alone, you will not know where (4, 4) was derived from.
In other words, (4, 4) appears to be the next hand of (3, 1), but the possibility of the next hand of (3, 2) is also possible.

(0, 0)->(1, 0)->(2, 0)->(3, 0)->(4, 0)->(5, 0) // Line 0 Eye
                           L>(3, 1)->(4, 1)->(5, 1) // first line
                 L>(2, 2)->(3, 2)->(4, 2)->(5, 2) // 2nd line
                                     L>(4, 3)->(5, 3) // 3rd line
                                     L>(4, 4)->(5, 4) // 4th line


I hope my understanding is insufficient. If so, please point out.

I feel like it would be nice to have your own serial number (id) and the previous serial number (id) at the start of the struct as an alternative.
I don't see it yet, but I'm going to go along that route.
We will report any progress.

We are looking forward to your answers and advice.

Added (2019.11.26 8:41)

I tried to change the way of holding data with the advice of MasatoUchida.
For simplicity, the stone color and coordinates are omitted, and the start number (id) and the next start (array of ids) are given.
An error occurs when it is a struct.
That's the code below.

var serial number: Int = 0
class start {
    var Start number: Int
    var Next start: [Start]
    init () {
        self.Start number = serial number
        self.Next start = []
        Serial number + = 1
    }
    func append (Next: Start) {
        self.next start.append (next start)
    }
    func print () {
        if next start.count == 0 {
            Swift.print (self.} else {
            for i in 0 ..<Next start.count {
                if Next start [i] .Start number == 4 {
                }
                Swift.print (self.Start number, "-", separator: "", terminator: "")
                Next start [i] .print ()
            }
        }
    }
}
let game score = start ()
let A = start ()
let B = Start ()
let C = Start ()
let D = start ()
let E = start ()
let F = start ()
let G = start ()
let H = start ()
let I = start ()
let J = undertake ()
let K = Start ()
Append (Next Start: A)
A.append (Next step: B)
A.append (Next start: C)
B.append (Next Start: D)
D.append (Next start: G)
D.append (Next start: H)
D.append (Next start: I)
C.append (Next start: E)
C.append (Next start: F)
F.append (Next start: J)
F.append (Next start: K)
棋 录 .print ()

When you do this,

0-1-2-4-7
4-8
4-9
1-3-5
3-6-10
6-11


It will be displayed.
Really

0-1-2-4-7
      | L 8
      | L 9
      L 3-5
          L 6-10
              L 11


I want to display it like this, but it's ok because it is not related to the main line.

There is no undo () written in the code above, but I think that this is the basic form because you can jump to any start instead of just going back.

Thanks for your advice and answers.

Please let us know if the source is dirty or wasteful.