home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Mac Power 1996 June
/
MACPOWER-1996-06.ISO.7z
/
MACPOWER-1996-06.ISO
/
MacPowerオリジナル
/
キョービのプログラマー
/
リバースクライアント東山1
/
東山通り.proj
/
reverseUtils.INCL
< prev
Wrap
Text File
|
1996-04-01
|
4KB
|
134 lines
'--------------------------------------------------
'----------------- ReverseUtils.INCL -------------
'------------- Reverse Client Program -------------
'--------------------------------------------------
' Original C version by Takuji Matsubara
' FutureBASIC II porting by Takayuki Nakano
'--------------------------------------------------
GLOBALS "reverseClient.GLBL"
END GLOBALS
INCLUDE FILE _aplIncl
'--------------------------------------------------
DEF FN readBoard(orec&,h,v) = PEEK(orec& + _board + h*_BoardSize + v)
LOCAL FN countRvStoneOne(orec&, dat&, nData)
XREF dat%(_BoardSize)
'----------
willReverse& = 0
terminaterFound% = _false
i=0
WHILE i < nData
LONG IF dat%(i) = _EmptyCell
i = nData 'break loop
XELSE
LONG IF dat%(i) = orec&.myStoneR&
terminaterFound% = _true
i = nData 'break loop
XELSE
INC(willReverse&)
END IF
END IF
INC(i)
WEND
IF terminaterFound% = _false THEN willReverse& = 0
END FN = willReverse&
LOCAL
DIM workData%(_BoardSize)
LOCAL FN countReverseStone(orec&, whichCell&)
willReverse& = 0
LONG IF FN readBoard(orec&, whichCell&.h%, whichCell&.v%) = _EmptyCell
'------ right (h++) -----------------------------------
i=0 : h = whichCell&.h% + 1
WHILE h < _BoardSize
workData%(i) = FN readBoard(orec&, h, whichCell&.v%)
INC(i) : INC(h)
WEND
willReverse& = willReverse& + FN countRvStoneOne(orec&, @workData%(0), i)
'------ left (h--) -----------------------------------
i=0 : h = whichCell&.h% - 1
WHILE h >= 0
workData%(i) = FN readBoard(orec&, h ,whichCell&.v%)
INC(i) : DEC(h)
WEND
willReverse& = willReverse& + FN countRvStoneOne(orec&, @workData%(0), i)
'------ bottom (v++) -----------------------------------
i=0 : v = whichCell&.v% + 1
WHILE v < _BoardSize
workData%(i) = FN readBoard(orec&, whichCell&.h%, v)
INC(i) : INC(v)
WEND
willReverse& = willReverse& + FN countRvStoneOne(orec&, @workData%(0), i)
'------ top (v--) -----------------------------------
i=0 : v = whichCell&.v% - 1
WHILE v >= 0
workData%(i) = FN readBoard(orec&, whichCell&.h%, v)
INC(i) : DEC(v)
WEND
willReverse& = willReverse& + FN countRvStoneOne(orec&, @workData%(0), i)
'------ right-bottom (h++ v++) -----------------------------------
i=0 : h = whichCell&.h% + 1 : v = whichCell&.v% + 1
WHILE h < _BoardSize AND v < _BoardSize
workData%(i) = FN readBoard(orec&, h, v)
INC(i) : INC(h) : INC(v)
WEND
willReverse& = willReverse& + FN countRvStoneOne(orec&, @workData%(0), i)
'------ right-top (h++ v--) -----------------------------------
i=0 : h = whichCell&.h% + 1 : v = whichCell&.v% - 1
WHILE h < _BoardSize AND v >= 0
workData%(i) = FN readBoard(orec&, h, v)
INC(i) : INC(h) : DEC(v)
WEND
willReverse& = willReverse& + FN countRvStoneOne(orec&, @workData%(0), i)
'------ left-bottom (h-- v++) -----------------------------------
i=0 : h = whichCell&.h% - 1 : v = whichCell&.v% + 1
WHILE h >= 0 AND v < _BoardSize
workData%(i) = FN readBoard(orec&, h, v)
INC(i) : DEC(h) : INC(v)
WEND
willReverse& = willReverse& + FN countRvStoneOne(orec&, @workData%(0), i)
'------ left-top (h-- v--) -----------------------------------
i=0 : h = whichCell&.h% - 1 : v = whichCell&.v% - 1
WHILE h >= 0 AND v >= 0
workData%(i) = FN readBoard(orec&, h, v)
INC(i) : DEC(h) : DEC(v)
WEND
willReverse& = willReverse& + FN countRvStoneOne(orec&, @workData%(0), i)
END IF
END FN = willReverse&
LOCAL FN getPlaceInfo(orec&, pinfo&)
pinfoPt& = pinfo& + _pt
'XREF pinfoPt.4(_MaxPlaceableCell) '<-- this causes bus error
pinfoNReverse& = pinfo& + _nReverse
XREF pinfoNReverse&(_MaxPlaceableCell) 'enables array in record
'----------
pinfo&.nCell& = 0
h=0
WHILE h < _BoardSize
v=0
WHILE v < _BoardSize
% pinfoPt& + _h + pinfo&.nCell& *4, h '<-- pinfoPt.h%(pinfo&.nCell&) = h&
% pinfoPt& + _v + pinfo&.nCell& *4, v '<-- pinfoPt.v%(pinfo&.nCell&) = v&
pinfoNReverse&(pinfo&.nCell&) = FN countReverseStone(orec&, pinfoPt& + pinfo&.nCell& *4)
IF pinfoNReverse&(pinfo&.nCell&) > 0 THEN INC(pinfo&.nCell&)
INC(v)
WEND
INC(h)
WEND
END FN = pinfo&.nCell&
'------------- utilities by t-nakano -------------
LOCAL FN countStone(orec&)
count% = 0
FOR v=0 TO _BoardSize-1
FOR h=0 TO _BoardSize-1
IF FN readBoard(orec&,h,v) THEN INC(count%)
NEXT
NEXT
END FN = count%