コンピュータ対戦です。
codereposに上げる予定なので、この本文のソースは古くなるかもしれません。
" Global Variables:
let s:CompScore=0
let s:UserScore=0
let s:StageMap = ""
let s:CompCoin = "o"
let s:UserCoin = "x"
let s:NullCoin = "."
command! -nargs=* Reverse call s:InitStage()
function! s:InitStage()
let s:StageMap = ""
let l:ycnt = 0
while l:ycnt <= 7
let l:xcnt = 0
while l:xcnt <= 7
if (l:xcnt == 3 && l:ycnt == 4) || (l:xcnt == 4 && l:ycnt == 3)
let s:StageMap = s:StageMap . "o"
elseif (l:xcnt == 3 && l:ycnt == 3) || (l:xcnt == 4 && l:ycnt == 4)
let s:StageMap = s:StageMap . "x"
else
let s:StageMap = s:StageMap . "."
endif
let l:xcnt = l:xcnt + 1
endwhile
let l:ycnt = l:ycnt + 1
endwhile
let s:CompScore=2
let s:UserScore=2
call s:MakeStage()
nnoremap <buffer> <2-leftmouse> :call <SID>PlayUser(1)<cr>
nnoremap <buffer> <space> :call <SID>PlayUser(1)<cr>
nnoremap <buffer> <esc> :call <SID>PlayUser(0)<cr>
nnoremap <buffer> q :close<cr>
echomsg s:UserCoin . " user : thinking..."
endfunction
function! s:MakeStage()
"put! s:StageMap
let save_f = @f
let @f = ""
let @f = @f . "+----------------+\n"
let l:ycnt = 0
while l:ycnt <= 7
let l:xcnt = 0
let @f = @f . "|"
while l:xcnt <= 7
let @f = @f . strpart(s:StageMap,l:ycnt*8+l:xcnt,1) . " "
let l:xcnt = l:xcnt + 1
endwhile
let @f = @f . "|\n"
let l:ycnt = l:ycnt + 1
endwhile
let @f = @f . "+----------------+\n"
if bufloaded("Reverse")
edit "Reverse"
silent %d _
else
silent execute "10split Reverse"
setlocal noswapfile
setlocal buftype=nowrite
setlocal bufhidden=delete
endif
silent put! f
let @f = save_f
execute "set titlestring=Reverse"
endfunction
function! s:SnapCoin( where, self )
let l:stage_tmp = strpart(s:StageMap,0,a:where)
let l:stage_tmp = l:stage_tmp . a:self
let l:stage_tmp = l:stage_tmp . strpart(s:StageMap,a:where+1)
let s:StageMap = l:stage_tmp
call s:MakeStage()
endfunction
function! s:PickCoin( where )
return strpart(s:StageMap,a:where,1)
endfunction
function! s:LookCoin( where, self )
let l:N = 0
let l:S = 0
let l:W = 0
let l:E = 0
let l:NW = 0
let l:NE = 0
let l:SW = 0
let l:SE = 0
if strpart(s:StageMap,a:where,1) != "."
return 0
else
if ( ( a:where - a:where % 8 ) / 8 ) > 1
let l:N = s:North( a:where,a:self )
endif
if ( ( a:where - a:where % 8 ) / 8 ) < 6
let l:S = s:South( a:where,a:self )
endif
if a:where % 8 > 1
let l:W = s:West( a:where,a:self )
endif
if a:where % 8 < 6
let l:E = s:East( a:where,a:self )
endif
if ( ( ( a:where - a:where % 8 ) / 8 ) > 1 ) && ( a:where % 8 > 1 )
let l:NW = s:NorthWest( a:where,a:self )
endif
if ( ( ( a:where - a:where % 8 ) / 8 ) > 1 ) && ( a:where % 8 < 6 )
let l:NE = s:NorthEast( a:where,a:self )
endif
if ( ( ( a:where - a:where % 8 )/8 ) < 6 ) && ( a:where % 8 > 1 )
let l:SW = s:SouthWest( a:where,a:self )
endif
if ( ( ( a:where - a:where % 8 )/8 ) < 6 ) && ( a:where % 8 < 6 )
let l:SE = s:SouthEast( a:where,a:self )
endif
"echo "nw=".l:NW."\n"
"echo "ne=".l:NE."\n"
"echo "sw=".l:SW."\n"
"echo "se=".l:SE."\n"
"echo "s=".l:S."\n"
if l:N + l:S + l:W + l:E + l:NW + l:NE + l:SW + l:SE == 0
return 0
else
call s:MakeStage()
return 1
endif
endif
endfunction
function! s:North( where,self )
let l:chk = 0
let l:pos = a:where - 8
while l:pos >= 0
if s:PickCoin(l:pos) == a:self
if l:chk != 0
let l:cnt = a:where
while l:cnt > l:pos
call s:SnapCoin(l:cnt,a:self)
let l:cnt = l:cnt - 8
endwhile
return 1
else
return 0
endif
elseif s:NullCoin.a:self !~ s:PickCoin(l:pos)
let l:chk = 1
else
return 0
endif
let l:pos = l:pos - 8
endwhile
return 0
endfunction
function! s:South( where,self )
let l:chk = 0
let l:pos = a:where + 8
while l:pos <= 63
if s:PickCoin(l:pos) == a:self
if l:chk != 0
let l:cnt = a:where
while l:cnt < l:pos
call s:SnapCoin(l:cnt,a:self)
let l:cnt = l:cnt + 8
endwhile
return 1
else
return 0
endif
elseif s:NullCoin.a:self !~ s:PickCoin(l:pos)
let l:chk = 1
else
return 0
endif
let l:pos = l:pos + 8
endwhile
return 0
endfunction
function! s:West( where,self )
let l:chk = 0
let l:pos = a:where - 1
while l:pos >= (a:where - a:where % 8)
if s:PickCoin(l:pos) == a:self
if l:chk != 0
let l:cnt = a:where
while l:cnt > l:pos
call s:SnapCoin(l:cnt,a:self)
let l:cnt = l:cnt - 1
endwhile
return 1
else
return 0
endif
elseif s:NullCoin.a:self !~ s:PickCoin(l:pos)
let l:chk = 1
else
return 0
endif
let l:pos = l:pos - 1
endwhile
return 0
endfunction
function! s:East( where,self )
let l:chk = 0
let l:pos = a:where + 1
while l:pos <= (a:where - a:where % 8 + 7)
if s:PickCoin(l:pos) == a:self
if l:chk != 0
let l:cnt = a:where
while l:cnt < l:pos
call s:SnapCoin(l:cnt,a:self)
let l:cnt = l:cnt + 1
endwhile
return 1
else
return 0
endif
elseif s:NullCoin.a:self !~ s:PickCoin(l:pos)
let l:chk = 1
else
return 0
endif
let l:pos = l:pos + 1
endwhile
return 0
endfunction
function! s:NorthWest( where,self )
let l:chk = 0
let l:pos = a:where - 9
while l:pos >= 0
if s:PickCoin(l:pos) == a:self
if l:chk != 0
let l:cnt = a:where
while l:cnt > l:pos
call s:SnapCoin(l:cnt,a:self)
let l:cnt = l:cnt - 9
endwhile
return 1
else
return 0
endif
elseif s:NullCoin.a:self !~ s:PickCoin(l:pos)
if (l:pos % 8) == 0 || ((l:pos - l:pos % 8) / 8) == 0
return 0
else
let l:chk = 1
let l:pos = l:pos - 9
endif
else
return 0
endif
endwhile
return 0
endfunction
function! s:NorthEast( where,self )
let l:chk = 0
let l:pos = a:where - 7
while l:pos >= 0
if s:PickCoin(l:pos) == a:self
if l:chk != 0
let l:cnt = a:where
while l:cnt > l:pos
call s:SnapCoin(l:cnt,a:self)
let l:cnt = l:cnt - 7
endwhile
return 1
else
return 0
endif
elseif s:NullCoin.a:self !~ s:PickCoin(l:pos)
if l:pos % 8 == 7 || (l:pos - l:pos % 8) / 8 == 0
return 0
else
let l:chk = 1
let l:pos = l:pos - 7
endif
else
return 0
endif
endwhile
return 0
endfunction
function! s:SouthEast( where,self )
let l:chk = 0
let l:pos = a:where + 7
while l:pos <= 63
if s:PickCoin(l:pos) == a:self
if l:chk != 0
let l:cnt = a:where
while l:cnt < l:pos
call s:SnapCoin(l:cnt,a:self)
let l:cnt = l:cnt + 7
endwhile
return 1
else
return 0
endif
elseif s:NullCoin.a:self !~ s:PickCoin(l:pos)
if l:pos % 8 == 0 || (l:pos - l:pos % 8) / 8 == 7
return 0
else
let l:chk = 1
let l:pos = l:pos + 7
endif
else
return 0
endif
endwhile
return 0
endfunction
function! s:SouthWest( where,self )
let l:chk = 0
let l:pos = a:where + 9
while l:pos <= 63
if s:PickCoin(l:pos) == a:self
if l:chk != 0
let l:cnt = a:where
while l:cnt < l:pos
call s:SnapCoin(l:cnt,a:self)
let l:cnt = l:cnt + 9
endwhile
return 1
else
return 0
endif
elseif s:NullCoin.a:self !~ s:PickCoin(l:pos)
if l:pos % 8 == 0 || (l:pos - l:pos % 8) / 8 == 9
return 0
else
let l:chk = 1
let l:pos = l:pos + 9
endif
else
return 0
endif
endwhile
return 0
endfunction
function! s:PlayUser(snap)
if a:snap == 1
let l:pret = s:LookCoin((line(".")-2)*8+(col(".")-2)/2,s:UserCoin)
redraw
if l:pret == 0
echo "Oops. You can't put on here."
return
else
let s:UserScore = s:UserScore + l:pret
echo s:UserCoin . " user: done"
endif
endif
echo s:CompCoin . " comp: thinking..."
1sleep
let l:pret = s:PlayComp()
redraw
if l:pret == 0
echo s:CompCoin . " comp: pass"
else
let s:CompScore = s:CompScore + l:pret
echo s:CompCoin . " comp: done"
endif
"execute "set titlestring=Reverse\\ ".s:UserScore.":".s:CompScore
endfunction
function! s:PlayComp()
let l:cget=s:LookCoin(0,s:CompCoin)
if l:cget > 0
return l:cget
endif
let l:cget=s:LookCoin(7,s:CompCoin)
if l:cget > 0
return l:cget
endif
let l:cget=s:LookCoin(56,s:CompCoin)
if l:cget > 0
return l:cget
endif
let l:cget=s:LookCoin(63,s:CompCoin)
if l:cget > 0
return l:cget
endif
let l:cget=s:LookCoin(2,s:CompCoin)
if l:cget > 0
return l:cget
endif
let l:cget=s:LookCoin(5,s:CompCoin)
if l:cget > 0
return l:cget
endif
let l:cget=s:LookCoin(16,s:CompCoin)
if l:cget > 0
return l:cget
endif
let l:cget=s:LookCoin(23,s:CompCoin)
if l:cget > 0
return l:cget
endif
let l:cget=s:LookCoin(40,s:CompCoin)
if l:cget > 0
return l:cget
endif
let l:cget=s:LookCoin(47,s:CompCoin)
if l:cget > 0
return l:cget
endif
let l:cget=s:LookCoin(58,s:CompCoin)
if l:cget > 0
return l:cget
endif
let l:cget=s:LookCoin(61,s:CompCoin)
if l:cget > 0
return l:cget
endif
let l:cget=s:LookCoin(3,s:CompCoin)
if l:cget > 0
return l:cget
endif
let l:cget=s:LookCoin(4,s:CompCoin)
if l:cget > 0
return l:cget
endif
let l:cget=s:LookCoin(24,s:CompCoin)
if l:cget > 0
return l:cget
endif
let l:cget=s:LookCoin(31,s:CompCoin)
if l:cget > 0
return l:cget
endif
let l:cget=s:LookCoin(32,s:CompCoin)
if l:cget > 0
return l:cget
endif
let l:cget=s:LookCoin(39,s:CompCoin)
if l:cget > 0
return l:cget
endif
let l:cget=s:LookCoin(59,s:CompCoin)
if l:cget > 0
return l:cget
endif
let l:cget=s:LookCoin(60,s:CompCoin)
if l:cget > 0
return l:cget
endif
let l:cget=s:LookCoin(1,s:CompCoin)
if l:cget > 0
return l:cget
endif
let l:cget=s:LookCoin(6,s:CompCoin)
if l:cget > 0
return l:cget
endif
let l:cget=s:LookCoin(8,s:CompCoin)
if l:cget > 0
return l:cget
endif
let l:cget=s:LookCoin(15,s:CompCoin)
if l:cget > 0
return l:cget
endif
let l:cget=s:LookCoin(48,s:CompCoin)
if l:cget > 0
return l:cget
endif
let l:cget=s:LookCoin(55,s:CompCoin)
if l:cget > 0
return l:cget
endif
let l:cget=s:LookCoin(57,s:CompCoin)
if l:cget > 0
return l:cget
endif
let l:cget=s:LookCoin(62,s:CompCoin)
if l:cget > 0
return l:cget
endif
let l:cget=s:LookCoin(18,s:CompCoin)
if l:cget > 0
return l:cget
endif
let l:cget=s:LookCoin(21,s:CompCoin)
if l:cget > 0
return l:cget
endif
let l:cget=s:LookCoin(42,s:CompCoin)
if l:cget > 0
return l:cget
endif
let l:cget=s:LookCoin(45,s:CompCoin)
if l:cget > 0
return l:cget
endif
let l:cget=s:LookCoin(19,s:CompCoin)
if l:cget > 0
return l:cget
endif
let l:cget=s:LookCoin(20,s:CompCoin)
if l:cget > 0
return l:cget
endif
let l:cget=s:LookCoin(26,s:CompCoin)
if l:cget > 0
return l:cget
endif
let l:cget=s:LookCoin(29,s:CompCoin)
if l:cget > 0
return l:cget
endif
let l:cget=s:LookCoin(34,s:CompCoin)
if l:cget > 0
return l:cget
endif
let l:cget=s:LookCoin(37,s:CompCoin)
if l:cget > 0
return l:cget
endif
let l:cget=s:LookCoin(43,s:CompCoin)
if l:cget > 0
return l:cget
endif
let l:cget=s:LookCoin(44,s:CompCoin)
if l:cget > 0
return l:cget
endif
let l:cget=s:LookCoin(10,s:CompCoin)
if l:cget > 0
return l:cget
endif
let l:cget=s:LookCoin(13,s:CompCoin)
if l:cget > 0
return l:cget
endif
let l:cget=s:LookCoin(17,s:CompCoin)
if l:cget > 0
return l:cget
endif
let l:cget=s:LookCoin(22,s:CompCoin)
if l:cget > 0
return l:cget
endif
let l:cget=s:LookCoin(41,s:CompCoin)
if l:cget > 0
return l:cget
endif
let l:cget=s:LookCoin(46,s:CompCoin)
if l:cget > 0
return l:cget
endif
let l:cget=s:LookCoin(50,s:CompCoin)
if l:cget > 0
return l:cget
endif
let l:cget=s:LookCoin(53,s:CompCoin)
if l:cget > 0
return l:cget
endif
let l:cget=s:LookCoin(11,s:CompCoin)
if l:cget > 0
return l:cget
endif
let l:cget=s:LookCoin(12,s:CompCoin)
if l:cget > 0
return l:cget
endif
let l:cget=s:LookCoin(25,s:CompCoin)
if l:cget > 0
return l:cget
endif
let l:cget=s:LookCoin(30,s:CompCoin)
if l:cget > 0
return l:cget
endif
let l:cget=s:LookCoin(33,s:CompCoin)
if l:cget > 0
return l:cget
endif
let l:cget=s:LookCoin(38,s:CompCoin)
if l:cget > 0
return l:cget
endif
let l:cget=s:LookCoin(51,s:CompCoin)
if l:cget > 0
return l:cget
endif
let l:cget=s:LookCoin(52,s:CompCoin)
if l:cget > 0
return l:cget
endif
let l:cget=s:LookCoin(9,s:CompCoin)
if l:cget > 0
return l:cget
endif
let l:cget=s:LookCoin(14,s:CompCoin)
if l:cget > 0
return l:cget
endif
let l:cget=s:LookCoin(49,s:CompCoin)
if l:cget > 0
return l:cget
endif
let l:cget=s:LookCoin(54,s:CompCoin)
if l:cget > 0
return l:cget
endif
return 0
endfunction