vim中的五子棋游戏gomoku.vim

我玩游戏的水平很差,至今还停留在五子棋的阶段。以前不喜欢emacs,所以想把emacs的gomoku.el移植到vim中。后来逐渐习惯emacs了,这个程序也就只完成一半就停下了。等有时间在继续吧。或者谁有兴趣继续,请别忘记告诉我啊。


1
2 " Gomoku Game in VIM vi improved
3 " v0.1 2005-03-13 Jerry Fleming<jerryfleming@etaang.com>
4 " gomoku.el by: Philippe Schnoebelen <phs@lsv.ens-cachan.fr>
5 " adapted by: ESR, Daniel Pfeiffer <occitan@esperanto.org>
6
7 " COMMENT
8 " This game adopts the idea and algorithm of gomoku.el, which may be found
9 " in standard GNU GNU Emacs, Editor of Macros distribution. No restriction is made on the squares one
10 " may move to disable _force win_ in the TRUE Gomoku, because I have no idea
11 " how one can force win at all. If you guys do, please let me know.
12
13 " some vars that you may change to fix your screen
14 let s:width = 128 " columns of text your screen can display
15 let s:height = 48 " rows of text your screen can display
16 let s:player = "X" " the piece-shape for a play
17 let s:robot = "0" " the piece-shape for the robot
18 let s:grid = "." " the mark of a square position
19 let s:gridwidth = 3 " the width of the grid, which should be less than 5;
20 " otherwise you can only see a very small set of grids
21
22 " PLAYING
23 " use h,l,j,k keys to move around as you would normally do in vimming, and press
24 " space bar where you see you are likely to win
25
26
27 """
28 """ IMPORTANT: you should not edit below whithout aware what you are doing
29 """
30
31 " since we deliberately makes the board four times of the screen, we should turn
32 " wrap off to see only a _windowed_ central part of the board
33 set wrap!
34 " we'd better set whichwrap so as to move freely with h,l,j,k
35 set ww=h,l,b,s
36 " the cmdheight might be changed, so we set it back
37 set ch=1
38
39 " initialize the board
40 let s:count= 0
41 while s:count < s:gridwidth - 1
42 let s:grid = s:grid . " "
43 let s:count = s:count + 1
44 endwhile
45
46 let @" = s:grid
47 let s:count = 0
48 while s:count < s:width / s:gridwidth
49 normal p
50 let s:count = s:count + 1
51 endwhile
52
53 let s:count=0
54 normal yy
55 while s:count < s:height - 1
56 normal p
57 let s:count = s:count + 1
58 endwhile
59
60 normal gg
61 let s:count=0
62 while s:count < s:height - 1
63 let s:i = s:gridwidth - 2
64 while s:i > 0
65 normal jd$
66 let s:i = s:i -1
67 endwhile
68 normal j
69 let s:count = s:count + 1
70 endwhile
71
72 normal gg0
73
74 " keymap to move s:gridwidth at a time and make your turn
75 let @x = s:player
76 noremap <Space> x"xPh
77 noremap l e
78 noremap h ge
79 " Gary Johnson <garyjohn@spk.agilent.com> contributed the following maps
80 noremap j :let q=col(".")<CR>$:call search('/S','W')<CR>:exec "normal" q."/|"<CR>:echo ""<CR>
81 noremap k :let q=col(".")<CR>0:call search('/S','bW')<CR>:exec "normal" q."/|"<CR>:echo ""<CR>
82 " save game session
83 noremap s :w! .vimgomoku<CR>
84 " abort game
85 noremap q :q!<CR>
86 " save and exit
87 noremap x :wq! .vimgomoku<CR>
88 " read saved session
89 noremap r ggdG:r .vimgomoku<CR>
90 " new game
91 noremap n ggdG:source gomoku.VIM<CR>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值