' Goban 0.4
' Copyright (c) 2009, 2010, 2012 Nonki Takahashi. All rights reserved.
'
' History :
' 0.4 2012/10/31 Rewrote in English. (RHV135-0)
' 0.3 2012/10/27 Rewrote in English. (RHV135)
' 0.2 2010/07/07 Minor changed (from [y][x] to [x][y]).
' 0.1 2010/06/29 Converted from goban.java written in 2009.
'
GraphicsWindow.Title = "Goban 0.4"
' constant
SPACE = 0 ' null point (no stone exists)
BLACK = 1 ' black stone
WHITE = 2 ' white stone
OB = 3 ' out of board
CRLF = Text.GetCharacter(13) + Text.GetCharacter(10) ' carriage return and line feed
' initialize go board
ro = 5 ' how much lines?
InitBoard()
turn = BLACK
DrawBoard()
' initialize game record
GraphicsWindow.FontSize = 12
GraphicsWindow.FontBold = "False"
record = Controls.AddMultiLineTextBox(xb0, yb1 + dy)
Controls.SetSize(record, GraphicsWindow.Width - xb0 * 2, dy * 7)
GraphicsWindow.FontBold = "True"
GraphicsWindow.MouseUp = OnMouseUp
continue = "True"
While continue
If clicked Then
clicked = "False"
Sound.PlayClickAndWait()
' draw (or remove) stone on mouse click
GetPos()
If onboard Then
GetStone()
If (color = SPACE) Then
color = turn
PutStone()
If turn = BLACK Then
turn = WHITE
Else
turn = BLACK
EndIf
Else
color = SPACE
PutStone()
EndIf
Else
If turn = BLACK Then
turn = WHITE
sgf = sgf + ";B[]"
moves = moves + 1
If Math.Remainder(moves, 10) = 0 Then
sgf = sgf + CRLF
EndIf
Controls.SetTextBoxText(record, sgf)
Else
turn = BLACK
sgf = sgf + ";W[]"
moves = moves + 1
If Math.Remainder(moves, 10) = 0 Then
sgf = sgf + CRLF
EndIf
Controls.SetTextBoxText(record, sgf)
EndIf
EndIf
ShowTurn()
Else
Program.Delay(100)
EndIf
EndWhile
Sub ShowTurn
' shows next turn
GraphicsWindow.FontSize = 20
If turn = BLACK Then
Shapes.HideShape(turnw)
Shapes.ShowShape(turnb)
Else ' If turn = WHITE Then
Shapes.HideShape(turnb)
Shapes.ShowShape(turnw)
EndIf
EndSub
Sub OnMouseUp
x = GraphicsWindow.MouseX
y = GraphicsWindow.MouseY
clicked = "True"
EndSub
Sub InitBoard
' initializes igo board
' param ro - number of ro
' work x, y
' work i
' work ds - offset of shadow
' return ro0, ro1 - positions of stars
' return x0, x1, dx - offset of first line, duration between lines
' return y0, y1, dy - offset of first line, duration between lines
' return bd[][] - igo board
' return mv[] - alphabet for game record
' return rs - radius of stone
ro0 = (ro + 1) / 4 ' position of star
ro1 = (ro + 1) / 2 ' position of star
x0 = 40 ' offset of first line
dx = 30 ' duration between lines
x1 = x0 + (ro - 1) * dx
y0 = 40 ' offset of first line
dy = 30 ' duration between lines
y1 = y0 + (ro - 1) * dy
rs = dx / 2 - 1 ' radius of stone
ds = 3 ' offset of shadow
stone = "" ' stone shape
shadow = "" ' shadow shape
For y = 1 To ro
For x = 1 To ro
bd[x][y] = SPACE
sx = x0 + (x - 1) * dx - rs
sy = y0 + (y - 1) * dy - rs
GraphicsWindow.PenWidth = 0
GraphicsWindow.BrushColor = "Black" ' shadow color
shadow[x][y] = Shapes.AddEllipse(2 * rs, 2 * rs)
Shapes.Move(shadow[x][y], sx + ds, sy + ds)
Shapes.SetOpacity(shadow[x][y], 50)
Shapes.HideShape(shadow[x][y])
EndFor
EndFor
For i = 0 To ro + 1
bd[i][0] = OB
bd[i][ro + 1] = OB
bd[0][i] = OB
bd[ro + 1][i] = OB
EndFor
For i = 0 To ro
' alphabet for SGF game record
mv[i] = Text.GetSubText(" abcdefghijklmnopqrs", i + 1, 1)
EndFor
EndSub
Sub PutStone
' puts stone on board
' param col - column
' param row - row
' param color - stone color
' param mv[] - alphabet for SGF game record
If (0 < col) And (col <= ro) And (0 < row) And (row <= ro) Then
bd[col][row] = color
If color = BLACK Then
sgf = sgf + ";B[" + mv[col] + mv[row] + "]"
moves = moves + 1
If Math.Remainder(moves, 10) = 0 Then
sgf = sgf + CRLF
EndIf
Controls.SetTextBoxText(record, sgf)
DrawStone()
ElseIf color = WHITE Then
sgf = sgf + ";W[" + mv[col] + mv[row] + "]"
moves = moves + 1
If Math.Remainder(moves, 10) = 0 Then
sgf = sgf + CRLF
EndIf
Controls.SetTextBoxText(record, sgf)
DrawStone()
ElseIf color = SPACE Then
RemoveStone()
EndIf
EndIf
EndSub
Sub GetStone
' returns color of stone
' param col - column
' param row - row
' return color - stone color
If (col >= 1) And (col <= ro) And (row >= 1) And (row <= ro) Then
color = bd[col][row]
Else
color = OB
EndIf
EndSub
Sub DrawStone
' draws stone on board
' param col - row
' param row - colomn
' param color - stone color
' param rs - radius of stone
' work ds - offset of shadow
' work sx, sy - left top coordinate of stone
' draw stone
sx = x0 + (col - 1) * dx - rs
sy = y0 + (row - 1) * dy - rs
Shapes.ShowShape(shadow[col][row])
If stone[col][row] = "" Then
GraphicsWindow.PenWidth = 0
If (color = BLACK) Then
GraphicsWindow.BrushColor = "Black" ' black stone color
ElseIf (color = WHITE) Then
rgb = GraphicsWindow.GetColorFromRGB(240, 240, 240)
GraphicsWindow.BrushColor = rgb ' white stone color
EndIf
stone[col][row] = Shapes.AddEllipse(2 * rs, 2 * rs)
Shapes.Move(stone[col][row], sx, sy)
If (color = BLACK) Then
GraphicsWindow.BrushColor = "Gray" ' high light color
ElseIf (color = WHITE) Then
GraphicsWindow.BrushColor = "White" ' high light color
EndIf
hilite[col][row] = Shapes.AddEllipse(rs / 2, rs / 2)
Shapes.Move(hilite[col][row], sx + rs / 2, sy + rs / 2)
Else
Shapes.ShowShape(stone[col][row])
Shapes.ShowShape(hilite[col][row])
EndIf
EndSub
Sub RemoveStone
' draws stone on board
' param col - row
' param row - colomn
Shapes.HideShape(shadow[col][row])
If stone[col][row] <> "" Then
Shapes.Remove(stone[col][row])
Shapes.Remove(hilite[col][row])
stone[col][row] = ""
hilite[col][row] = ""
EndIf
EndSub
Sub DrawBoard
' param x0, y0 - left and top
' work xb0, yb0 - left and top coordinate of board
' work xb1, yb1 - right and botton coordinate of board
' work i
' work xo, yo, xw, yw, xc, yc, rw, theta, xw0, xw1, yw0, yw1, x, y
' work r, g, b, rs
xb0 = x0 - dx ' left
yb0 = y0 - dy ' top
xb1 = x1 + dx ' right
yb1 = y1 + dy ' bottom
If GraphicsWindow.Width < xb1 + dx * 4 Then
GraphicsWindow.Width = xb1 + dx * 4
EndIf
If GraphicsWindow.Height < yb1 + dy / 3 Then
GraphicsWindow.Height = yb1 + dy / 3
EndIf
Sub GetPos
' gets column and row from mouse coordinate
' param x - mouse x coordinate
' param y -mouse y coordinate
' work rs - radius of stone
' return col, row - column and row on board
' return onboard - "True" if on board
rs = Math.Floor(dx / 2) - 1 ' radius of stone