Microsoft Small Basic

Program Listing: JVR185
' Igo02.smallbasic - Igo v0.2
'
' 履歴:
' v0.1 2010/07/21 初版:碁盤の表示 (243行 NBK992)
' v0.2 2010/05/05 手数の表示 (265行)
'
' work: boolean bProgramEnd - プログラム終了
' work: boolean bGameEnd - 終局
' work: integer iMove - 手数
'
' ゲームの初期化
InitGame()
' 対戦者名(または棋譜名)の入力
InputGameInfo()
' プログラム終了が指定されるまで{}内繰り返し
While (bProgramEnd = "False")
'{
' 盤の初期化
InitBoard()
' 棋譜の初期化
InitRecord()
' 盤の表示
ShowBoard()
iMove = 0
' 終局になるまで{}内繰り返し
While (bGameEnd = "False")
' {
iMove = iMove + 1
'  先手が打つ
Replay()
'  禁じ手なら再度打つ
'  棋譜の記録
'  盤の表示
DrawStone()
Sound.PlayClickAndWait()
'  終局の判定
Judge()
If bGameEnd Then
Goto lGameEnd
EndIf
'
iMove = iMove + 1
'  後手が打つ
Replay()
'  禁じ手なら再度打つ
'  棋譜の記録
'  盤の表示
DrawStone()
Sound.PlayClickAndWait()
'  終局の判定
Judge()
' }
EndWhile
lGameEnd:
' 対戦者名(または棋譜名)の入力
InputGameInfo()
bProgramEnd = "True"
' }
EndWhile
'
' ゲームの初期化
' out: integer iRo - 何路か
' out: real rCX - 文字幅
' out: real rCY - 文字の高さ
' out: integer iMove - 手数
' out: constant SPACE - 空点
' out: constant BLACK - 黒
' out: constant WHITE - 白
' out: constant OB - 盤外
Sub InitGame
SPACE = 0 ' 空点
BLACK = 1 ' 黒
WHITE = 2 ' 白
OB = 3 ' 盤外
iRo = 6
rCX = 15.6
rCY = 24
GraphicsWindow.FontSize = rCY
EndSub
'
' 対戦者名(または棋譜名)の入力
' out: boolean bShowMove - 手数を表示する
' out: boolean bGameEnd - 終局
' out: boolean bProgramEnd - プログラム終了
Sub InputGameInfo
bShowMove = "True"
bGameEnd = "False"
bProgramEnd = "False"
Program.Delay(2000)
EndSub
'
' 盤の初期化
' in: integer iRo - 何路か
' in: real rCX - 文字幅
' in: real rCY - 文字の高さ
' work: integer i, iX, iY
' out: integer iBoard[][] - 碁盤
' out: integer idLX, idLY - 線の間隔
' out: integer iSR - 碁石の半径
' out: integer iLX0, iLY0, iLX1, iLY1 - 左端, 上端, 右端, 下端の線
' out: integer iBX0, iBY0, iBX1, iBY1 - 盤の左端, 上端, 右端, 下端
Sub InitBoard
For i = 0 To iRo + 1
iBoard[0][i] = OB
iBoard[iRo + 1][i] = OB
iBoard[i][0] = OB
iBoard[i][iRo + 1] = OB
EndFor
For iX = 1 To iRo
For iY = 1 To iRo
iBoard[iX][iY] = SPACE
EndFor
EndFor
idLX = rCX * 3 ' 線の間隔
iSR = idLX / 2 - 2 ' 碁石の半径
idLY = rCY * 2 ' 線の間隔
iLX0 = rCX * 6.5 ' 左端の線
iLY0 = rCY * 4.5 ' 上端の線
iLX1 = iLX0 + idLX * (iRo - 1) ' 右端の線
iLY1 = iLY0 + idLY * (iRo - 1) ' 下端の線
iBX0 = iLX0 - idLX * 1.5 ' 盤の左端
iBY0 = iLY0 - idLY * 1.5 ' 盤の上端
iBX1 = iLX1 + idLX ' 盤の右端
iBY1 = iLY1 + idLY ' 盤の下端
EndSub
'
' 盤の表示
' in: integer idLX, idLY - 線の間隔
' in: integer iSR - 碁石の半径
' in: integer iLX0, iLY0, iLX1, iLY1 - 左端, 上端, 右端, 下端の線
' in: integer iBX0, iBY0, iBX1, iBY1 - 盤の左端, 上端, 右端, 下端
' work: integer iX, iY
Sub ShowBoard
' 盤の色を塗る
GraphicsWindow.BrushColor = "Wheat"
GraphicsWindow.FillRectangle(iBX0, iBY0, iBX1 - iBX0, iBY1 - iBY0)
' 線を描く
GraphicsWindow.PenColor = "Black"
For iX = iLX0 To iLX1 Step idLX
GraphicsWindow.DrawLine(iX, iLY0, iX, iLY1)
EndFor
For iY = iLY0 To iLY1 Step idLY
GraphicsWindow.DrawLine(iLX0, iY, iLX1, iY)
EndFor
' 数字を書く
GraphicsWindow.BrushColor = "Black"
For iX = 1 To iRo
GraphicsWindow.DrawText(iLX0 + (iX - 1.2) * idLX, iLY0 - idLY - 3, iX)
EndFor
For iY = 1 To iRo
GraphicsWindow.DrawText(iLX0 - idLX, iLY0 + (iY - 1.25) * idLY - 3, iY)
EndFor
EndSub
'
' 碁石を描く
' in: integer iX - 碁石のX座標
' in: integer iY - 碁石のY座標
' in: integer iColor - 碁石の色
' in: boolean bShowMove - 手数を表示する
' in: integer iMove - 手数
' work: iNX - 手数のX座標
' work: iNY - 手数のY座標
Sub DrawStone
If iColor = WHITE Then
GraphicsWindow.BrushColor = "White"
GraphicsWindow.FillEllipse(iLX0 + (iX - 1) * idLX - iSR, iLY0 + (iY - 1) * idLY - iSR, iSR * 2, iSR * 2)
If bShowMove Then
GraphicsWindow.BrushColor = "Black"
iNX = iLX0 + (iX - 1) * idLX - rCX / (2 - Math.Floor(iMove / 10))
iNY = iLY0 + (iY - 1) * idLY - rCY / 2 - 3
GraphicsWindow.DrawText(iNX, iNY, iMove)
EndIf
ElseIf iColor = BLACK Then
GraphicsWindow.BrushColor = "Black"
GraphicsWindow.FillEllipse(iLX0 + (iX - 1) * idLX - iSR, iLY0 + (iY - 1) * idLY - iSR, iSR * 2, iSR * 2)
If bShowMove Then
GraphicsWindow.BrushColor = "White"
iNX = iLX0 + (iX - 1) * idLX - rCX / (2 - Math.Floor(iMove / 10))
iNY = iLY0 + (iY - 1) * idLY - rCY / 2 - 3
GraphicsWindow.DrawText(iNX, iNY, iMove)
EndIf
EndIf
EndSub
'
' 棋譜の初期化
' out: integer iRecord[][] - 棋譜
' out: integer iNumRec - 棋譜の手数
Sub InitRecord
iRecord[1]["x"] = 4
iRecord[1]["y"] = 3
iRecord[1]["turn"] = BLACK
iRecord[2]["x"] = 3
iRecord[2]["y"] = 4
iRecord[2]["turn"] = WHITE
iRecord[3]["x"] = 4
iRecord[3]["y"] = 4
iRecord[3]["turn"] = BLACK
iRecord[4]["x"] = 3
iRecord[4]["y"] = 3
iRecord[4]["turn"] = WHITE
iRecord[5]["x"] = 3
iRecord[5]["y"] = 2
iRecord[5]["turn"] = BLACK
iRecord[6]["x"] = 2
iRecord[6]["y"] = 2
iRecord[6]["turn"] = WHITE
iRecord[7]["x"] = 4
iRecord[7]["y"] = 2
iRecord[7]["turn"] = BLACK
iRecord[8]["x"] = 4
iRecord[8]["y"] = 5
iRecord[8]["turn"] = WHITE
iRecord[9]["x"] = 5
iRecord[9]["y"] = 5
iRecord[9]["turn"] = BLACK
iRecord[10]["x"] = 4
iRecord[10]["y"] = 6
iRecord[10]["turn"] = WHITE
iRecord[11]["x"] = 5
iRecord[11]["y"] = 6
iRecord[11]["turn"] = BLACK
iRecord[12]["x"] = 2
iRecord[12]["y"] = 5
iRecord[12]["turn"] = WHITE
iRecord[13]["x"] = 2
iRecord[13]["y"] = 1
iRecord[13]["turn"] = BLACK
iRecord[14]["x"] = 1
iRecord[14]["y"] = 2
iRecord[14]["turn"] = WHITE
iRecord[15]["x"] = 3
iRecord[15]["y"] = 1
iRecord[15]["turn"] = BLACK
iRecord[16]["x"] = 2
iRecord[16]["y"] = 3
iRecord[16]["turn"] = WHITE
iRecord[17]["x"] = 1
iRecord[17]["y"] = 1
iRecord[17]["turn"] = BLACK
iNumRec = 17
EndSub
'
' 次の手を打つ
' in: integer iMove - 手番
' in: integer iRecord - 棋譜
' out: integer iX -
' out: integer iY -
' out: integer iColor -
' out: integer iBoard[][] - 碁盤
Sub Replay
iX = iRecord[iMove]["x"]
iY = iRecord[iMove]["y"]
iColor = iRecord[iMove]["turn"]
iBoard[iX][iY] = iColor
EndSub
'
' 棋譜の記録
'
' 終局の判定
' out: boolean bGameEnd - 終局
Sub Judge
If iMove = iNumRec Then
bGameEnd = "True"
EndIf
EndSub