2012年4月6日星期五

堆文的恶趣味

曾一直有断断续续地写些篇幅较短的小说作为娱乐,文字多为含含糊糊的叙述描写,风格大多只是为了体现某些方面趣味,内容有时语无伦次。
现在想这种趣味不能使得写出的文字有什么质量,不过缺失这种趣味的话,又觉得没什么自己来写的必要了。
既然定位于自娱自乐了,那么发扬之前的趣味来继续扩展一些,并学习一点新的趣味增添其中,还是一件蛮有趣味的事情吧。


* 趣味一 信息流动

即严格地在文本的阅读顺序中控制读者对整个故事知道什么,以怎样的顺序知道哪些事实,以及不同的事实之间存在着何种关联。
这就像有的侦探小说或者电影在观众的脑海里留下许多零散的画面片段,但是又巧妙的串联在一起,使得故事呈现出一种立体感。


* 趣味二 情节和叙述两条线索

故事情节本身是一条线索,而故事表现出来的是另一条线索,即叙事线和情节严格的分为两条线来处理。
叙事线本身也是一个有开端有发展有结局的故事,不过这个故事是作为叙述来使用的,而故事本身仍然是真正的故事情节本身。
通常来说可以用“寻找”“回忆”“失忆”“表现/真相”“历史/现实”这样的行为动机来构成表面的叙事线索。
一般让读者在读完整个故事后,能够在自己的脑海中补完一条连续的情节线出来,这个时候让叙事线淡化。


* 趣味三 故事的情节以设定来代替叙事

这个是关于情节构思方面的,即在构思的时候注重整理故事中的各个事件间的关联和关系,之间的影响以及是关于主题或话题的哪个方面的观点和视角。
并不一定要说情节就是构思发生的某个故事那样的,而是说情节本身是一种事实一种为了内容的需要而产生的一种设定。
文本故事性和趣味性可以通过叙事线来加强,而真正要讲述的故事本身是一多角度立体感的存在。


* 趣味四 人物的行为动机和人物间的影响

整个叙述过程之中,一直围绕着人物的自身行动的动机来展开,即由于人物自身的某种目的来进行行动来构成故事。
通常可以众多人物各自的行动都作为动机来推动叙事,并且人物之间的互动会使得各自的行动的动机发展并互相产生影响。
这种人物自身的动机的发展,是用来交代真正的情节线的一个很重要的手段,并且人物间的互动也是很主题之间相关的。


* 趣味五 叙事按照场景来划分,简化结构

按照场景来划分,每个场景有固定的发生的环境(固定的也可以是运动的,是整体即可),有场景参与的人物。
每个场景考虑交代了那些事实,又对叙事起到了怎样的推动作用,整个故事文本便通过这样若干场景以某种较为简单的结构构成。
本身已经已经在叙事线和情节线上够折腾的了,所以以场景构成的叙事线就一定要简单明了,并尽可能的简化。


* 趣味六 人物细腻的情感

故事的主题与话题是一方面,是作为文本的内容存在。而叙述的表现力是主要注重在人物的情感方面,包括人物对于自身,对于他人,对于现实,对于曾经所发生过的事情的看法观点态度情绪等等方面来作为故事所展现的风景的载体。


* 趣味七 世界观和历史观

整个故事的发生环境,简单的说就是非现实世界的日常故事。
即发生的环境可以是架空的,可以是科幻或奇幻,以及适合于适合于情节的在某种规则制约下的世界。不过就情节本身而言,要尽可能的呈现出一种属于日常的平平常常的故事那样的故事。
背景是明显虚构的,但是要让故事本身有种真实的在这个背景下发生着的样子,人物有各自的信仰和社会角色,而不是一个单薄的存在。
这个世界有其过去发生过去的事情,人们知道的事情,将来要面对的事情。每个人物也有过去的故事,这个过去的会成为他面对他人时的一个要素。
不同人物的过去现在以及未来都有交织的可能性,这种交织和发展,成为了故事的一个重要的叙事方式。
到底人物线怎么使用,是平行还是主次还是轮换还是其他的混合方式,这在实际运用中有发挥的余地。


* 趣味八 景色和对话

景色和对话都是很有表现力的情节叙述方式,不过要避免因为使用得不得当而造成地情节不明了或叙述的错乱。
景色和对话都是很适合让人物敞开心扉讲述属于他自己的故事的这样一种场景,用一种敞开心扉的态度来让人物和观众都作为一种读者的立场存在。
情节和对话也都是很容易用来推动情节的,侧重于用景色和对话来讲述真正的情节线即可。运用对话中的情绪和对话参与者间关于事实的互动来推动叙述。


* 趣味九 人物和读者的立场

让叙事线里的主角和读者都置于去获得整个故事的一种身份的这样一种一致的立场上。
明确在叙事之中考虑不同的人物各自找到什么以及读者知道什么,这样的信息与事实的传递会影响到整个故事的叙事过程中的每个人物(包括读者)的立场和动机。
当然不能限定死了读者的身份是怎样的,需要给读者自身存在感容纳和参与的众多余地。叙事线和情节线是一个方面,不过读者的整个阅读过程也是重要的体验与参与的过程,并同时有着旁观和亲历者的双重身份。这也是之前划分出单独的叙事线出来的一个理由所在。


* 趣味十 人物的性格刻画

这是需要的,很是需要的。有抽象的说是某类属性的人物,也有具体说是经历的哪些事情认识哪些人物以及对它们都有什么身份和态度来构成的一个人物。
不过性格特征明显一些的话人物就要容易辨认得多,这样也让情节的叙述明朗许多。
虽然个人很想在淡化情节和运用设定来展现情感方面寻找些许趣味,不过人物方面不小心就路人了的感觉。


* 趣味十一 节奏和音乐的氛围

其实就是指氛围了,在表面平淡的场景之中,有一种持续的氛围所笼罩,通常是抒情性的,还是不错的。


* 趣味十二 以故事来讲述对故事的看法

比如这里对于文本的趣味说了好些个人的喜好,其实这些喜好是可以通过一个具体的小说来展现出来,而不是这里通过文字的形式来说它是什么。
也就是说,故事文本是用来讲述对故事或者对于主题的一个多方面的审视的存在。既在以某种叙事方式讲述着一个故事,并同时以这样的一个故事表达着对于故事本身以及对于故事的叙述的方式的的一种看法。


* 趣味十三 故事的主题

这个通常老套一点就行了。比如成长友谊感情什么听起来乐观有趣鼓舞人心的的东西都可以。


* 趣味十四 短篇形式的篇幅

一个单独的完整的小故事即可,视角小些篇幅和情节都简化指留明了的主线相关物,然后故事也要有立体感。


* 其他的补充

看需要在补充吧。以上内容并没有好好的构思,只是想到什么然后就列为一点写下来了,也不知太片面或者考虑的不周全。
既然是作为一篇随手写写记录记录的东西,自己明知要改动的话可以让内容在明了和完整些许吧。
不过这里仅仅是流水的记录,记录下当前先想到的一些趣味的可能性,然后就不再继续,就暂且写到这里了吧。


-----


叙述之间从高潮部分插入,既故事一开始就是某个事件正在高潮的部分。然后再把故事具体的展开。这样先尽可能把把故事涉及的话题的全貌展示出来,然后再具体地增加立体感。

2012年3月24日星期六

本想写篇心情日记的

早上在床上被窝里缩了好久一直没起来,在这个安静的早晨里,感觉可以让脑子安静地去想象身边和周围的事情,于是就忽然有了有话说的感觉。如果刷微博的话确实是只言片语就了,不过想到咱是或许把微博更多地作为一个沟通和记录来用的话,在那种轻浮感之中来写日记只是觉得心里空荡荡的。于是还是起来打开电脑写写日志好了。
以上便是开场,然后正文什么的本该是继续写下去的。不过等到洗完澡抚摸着键盘的时候,却又感到自己变得拘谨起来。所谓心情这种东西,一方是源于自己的心里的想法,一方面也是出于对自身情境的掩饰。就像乐观有时不是因为对结果的肯定,而是因为有可为结果所做的行动并获得可预计的回报;就像悲观有时不是因为能力的不足或意外的挫折,而是因为有时对风险的一种自我保护中需要一种推脱的借口。于是其中重要的事情便变成了是在做出怎样的一种行为,而所谓心情什么的就只变成了行为的表现方式的一种附属物了。
所以说什么是满足什么是奢望,各自又会对应着什么样的行为,这是一件很微妙的事情。那些觉得一无是处不思进取的行为,或许就是值得骄傲并足以信赖的伙伴呢。并且在这同时可以再有一份心态,去创造机遇迎接变化便是了。
或许过多的折腾只是改变了塑料瓶的的形状,压缩了它的体积让水看起来可以满一些,不过可能其实水却流失了。空或满的感官对于结果而言只是参照,心情对于言语亦只是想法与心态的婉转表达,原本想到的那些思绪还是不打算具体地写成什么了。
这里,大体就写这些了。

https://twitter.com/#!/LennaHammer/status/183384888844632064

2012年2月17日星期五

存活确认

看了一下后台“编辑帖子”列表,里面有好多写废了的文,或者认为不适合发布的内容。
它们有的是开了个标题没写的,有的是涉及私事的,有的内容太幼稚的,有的在别处贴过的,有的涉及18x内容。
内容有长有短,目前帖数是占据了公开帖数的三分之一了,和生活里的经历一起,构成了海平面下的冰川。
最近是习惯在本地用文本编辑器编辑来再发出来,不知道那里还有什么写废的东西没。

不过自己都知道是些写废的或者不愿意贴出来的东西,在这里说出来看起来也没什么意义。
现在看大多数的博客或者日志之类都是想他人展现自己,一个积累并分享价值的一个平台吧。
不过,咱这里呀,咱是完全当一个私人空间来看待,当作一个自言自语的地方了。
甚至比推特微博之类的地方还要清静的感觉,一个可以容忍着自己继续幼稚或者犯傻的地方。

那些曾经想回避的话题,在这个草稿箱里依然是难寻踪迹。如果将来遗忘了,那就可能是真的永远的遗忘了。那些其中经历的不愉快,那些其中收获的快乐,或许有那么一天,将会永远的消失在记忆的深处了吧。

此刻,就总能想到一个孤单的身影呢。
一个人孤单的裹在被子里的小男孩,伸出头来,数着窗外天空里的那片星星。

----
久久,这里就没留下过什么了,这大概是荒废了吧。

----
回想过去的这半年——
奶奶病倒了,目前语言和记忆都受到印象,有些事情我这里先记着吧,暂时不写了。
准备了一场考试,可惜自己太没有勇气了,总是缩手缩脚的,这样可不行。
虽然最主要的事情便是忙这考试了,可以如果未达到的目的话,这半年的意义也就不明显了。
不过期间也看了一些书了,也算是有所收获吧,于是也可以欣慰一些。
坑了一个Scheme实现,初步实现了大体的功能,然后就一直坑着了。
UUShare关闭了,几年记忆的实物就这么消失了,谢谢河马的最后时刻备份。
开始用小号玩着推特和微博,谢谢啊七和河马的在使用上的帮助,留下点足迹。
在KeyFc申请了版主,详情以后写,算有点经历和想法吧,可惜自己不珍惜便被退了。
写了两篇文,一篇Clannad的同人当论坛活动,参与了一篇Key同人剧本,以后整理过来吧。
推了些许游戏和小说和动漫,不过进度都很慢来着。
现在想来,这些折腾的意义如何,也不甚明了了。
可是毕竟半年的时光过去了,就这样原原本本的写下来吧。
想做到很多事情,可是又无能为了,或者不愿去做,然后增加了许多烦恼吧。

----
想象近几天习惯了用刷推特微博来消磨时间了,大概也出于自身在很多方面无能为力的失落感吧。
这样便觉得自己所作的都是毫无意义,然后便对未来有了无助恐慌和害怕作出任何的事情了。

2012年1月1日星期日

几个感觉不错的应用

很水的一帖,翻了翻手机和硬盘,看看有什么好玩的东西。。。
* Stranded 一个孤岛生存类游戏,Win32
http://stranded.unrealsoftware.de/s2_infos.php
* RogueLight 很有冒险感觉的的rogue游戏,Win32
http://gamejolt.com/freeware/games/rpg/roguelight/1425/
* POWDER 一个地图紧凑的图形rogue游戏,按键少,PC/Mobile
http://www.zincland.com/powder/
* QDict Android平台的字典
http://mail.ustc.edu.cn/~wchao911/
* MDict WM平台的字典
http://www.octopus-studio.com/
* Cool Reader 简洁强大的电子书阅读器,Android平台
http://coolreader.org/e-index.htm
* MX Video Player Android上的视频播放器,媒体管理功能真心不错,自动生成列表记录媒体是否播放过播放到哪里
http://sites.google.com/site/mxvpen/
* RepliGo Reader Android上性能和不错的PDF阅读器,支持书签重排笔记
http://www.cerience.com/products/reader/
* Harmony 一个DOOM2的同人,怀旧感,Win32
http://www.rabotik.nl/
* Scratch 教学与原型的创造力,PC
http://scratch.media.mit.edu/
* AlReader 以前在WM手机上用的
http://www.alreader.com/
* TCPMP/CorePlayer 以前在WM手机上用的
http://corecodec.com/products/coreplayer/
* 云端 Win32上的应用虚拟化分发应用,还在用0.9版
http://yunduan.cn/
* RocketDock 放在桌面右边,然后把桌面图标关了
PuzzleCollectionPortable 一堆桌面解谜游戏
http://www.chiark.greenend.org.uk/~sgtatham/puzzles/
* BTLocal 貌似能用的搜索辅助工具
* minijoe 看着玩玩
http://code.google.com/p/minijoe/
* onscripter nscripter的开源实现,多平台
* wintersweet Win32上挺方便的字典
* dunwich 看着玩玩
http://marijnhaverbeke.nl/dunwich/
* Clark Productions 一个Basic的rogue游戏
http://users.freebasic-portal.de/rdc/programs.html
* MPlayer 必备
* 魔王录 有格子感的动作要素淡化的动作游戏
* 金庸群侠传console_rpg 字符游戏的感觉还挺不错的
http://code.google.com/p/flaswf/source/browse/trunk/JYtrpgYDZS/?r=223
* Notepad++ 文本编辑器,加tagview插件
* 简易三国志2 增强版 文本界面游戏?
http://ishare.iask.sina.com.cn/f/11573234.html
* everything 我已经不记得文件在哪个目录里了


OHRRPGCE
http://en.wikipedia.org/wiki/OHRRPGCE
monster2
http://www.nooskewl.com/node/29/
Gravity Bone
http://blendogames.com/
WinFF - Free Video Converter
http://winff.org/html_new/
漂亮同人堂
http://www.acgmix.net/web/index.htm
Simon Tatham's Portable Puzzle Collection
http://www.chiark.greenend.org.uk/~sgtatham/puzzles/
rocksndiamonds
http://www.artsoft.org/rocksndiamonds/
Ori, Ochi, Onoe
http://games.renpy.org/game/o3.shtml
StorytellingAlice
scummvm
leidao
mldonkey
mplayer
Audacity

2011年11月20日星期日

简易Roguelike制作流程【转/待译】

原文地址:roguebasin.roguelikedevelopment.org



How to Write a Roguelike in 15 Steps


This is a rough route map for the creators of roguelikes. I'm well aware that there are many possible routes and that no two journeys are the same -- this is a description of one of possibilities and maybe will help you to plan your own.
Please add your comments -- maybe we could make this article really helpful. What are your own routes?


Contents
1 Step 1 - Decide to write a game
2 Step 2 - Hello world!
3 Step 3 - It's a boy!
4 Step 4 - The map
5 Step 5 - Saving/Loading
6 Step 6 - It's alive! Alive!
7 Step 7 - Interaction
8 Step 8 - Data files
9 Step 9 - Items
10 Step 10 - Magic
11 Step 11 - Simple game
12 Step 12 - Levels
13 Step 13 - Experience
14 Step 14 - Citizens
15 Step 15 - Free at last


Step 1 - Decide to write a game

Most of you will have this step behind you already, but there are some hints about the direction of the first step. The best reason to start developing your own roguelike game is to create a game that you will enjoy playing yourself.
Don't start by asking around about the definition of roguelike game -- you don't need it. If the game you write is not considered roguelike by others, but it's still fun to play for you -- you succeeded. It's not like there's some kind of a contest to write a game meeting certain specifications.
Don't plan too much. Of course, if you want certain things in your game, you must write it so that there is room for them -- but don't even try to anticipate everything -- it's just impossible. When you write a design doc, you make a lot of decisions. Most of the decisions can't be made without performing some test first -- usually by writing small programs utilizing given feature. It's best to make the decisions when your project has already reached appropriate stage -- when you don't need to write an additional program, because your project already has everything you need.
It's no fun to just proceed according to plan -- leave some space for improvisation. Don't be afraid about making mistakes or implementing something in an inflexible way -- you can improve it when you need it -- most of the time it will be ok.


Step 2 - Hello world!

Prepare your programming environment. Choose your language and platform, choose appropriate compilers/interpreters, editor, version control, automated build, and other utilities. Set them up so that you're comfortable with them.
Decide on which libraries you're going to use -- it can change later, but it's usually a painful change. Don't think too much about portability -- it can be fixed later. Think about what you need and what you're comfortable with.
Decide on the language you want to write comments and object names in your code, as well as the language you want to be used in your game. It's strongly recommended to use English in your source code -- you can get more help this way from others.
Don't worry about i18n yet; translation is usually a very late step in the development process.
Write a simple 'Hello world!' program and test whether it works. Test your libraries, etc. -- you don't want any surprises.
Start coding.


Step 3 - It's a boy!

Start with screen output and keyboard input. Decide preemptively on your screen layout (easy, you can change it later) and make the routines that display map characters, status lines and messages.
Make the routine to read key-presses (no config files, no keys redefinition).
Make a '@ walking around the empty screen' demo. Play with it a little, clean things up, play some more, imagining the game is finished and you're playing it.
Make the message handling routines -- especially for the debugging messages -- they come in handy.


Step 4 - The map

Decide on your map structure. Don't over-generalize -- you can add things later. Make your (empty) map displayed on the screen. Scrolled if you need it. Add some elements to your map to see if they are displayed correctly (just hard-code them, you don't need a level generator yet).
Make your '@' appear on the map -- not as it's element at first, just as a cursor. Test the scrolling, maybe make a 'look' command.
Now turn '@' into creature. You still don't have time implemented, so the keyboard-reading routines will just move it around the map. Include the checks for walls in the movement code. Maybe add doors and open/close commands.


Step 5 - Saving/Loading

Read the map from a file instead of hard-coding it. You can play with it and test different configurations if you make it human-readable from the start.
Add the 'save' command and the procedures to save your game -- the map at first, then, gradually, all of other game elements. From now on, when you implement something that needs saving, also implement saving it as soon as possible.
Here's a handy article about save files and how to implement them; it's worthwhile to read when planning ahead what form you'll save things in.
Once you work with files, you can make your preferences and keybindings config files. Again, if you make them human-readable, you'll save yourself a lot of trouble.
Now, when you're not sure how any element of the game works, you can save the game to a file and just check it.


Step 6 - It's alive! Alive!

Implement other creatures (monsters) and time. Add a single monster to begin with. Give him some simple AI (like, say, stay still, or maybe move randomly).
Start with my turn-your turn, then implement the time system you want (or, usually, a simplification of it and gradually make it more complicated later).
Remember to test everything as you go.


Step 7 - Interaction

Add stats for your creatures. A simplification of the ones you envisioned, probably. It's best to add stats as they are needed, not because they 'look cool', but you might not be able to resist ;).
Make the creatures notice each other -- bump, attack, etc. Gradually improve their AIs, so that they can chase the player.
Implement and test the combat system -- without equipment for now, just hardcode the values. Do lots of testing.


Step 8 - Data files

Move the creature, map features, etc. definitions to data files. Forget about scripting for now If something cannot be moved -- just leave it for now.


Step 9 - Items

Add items. For start, just objects you can pick up -- no properties. Gradually give them properties, kinds, stats, etc., implement inventory, picking up and dropping, equipping and using (no effects yet), also stacking, containers (if you want them), etc.
This step usually requires lots of testing to balance.


Step 10 - Magic

Add item effects, special monster attacks, spells. Add items and monsters to test them. You don't need all the possible effects right away, just the ones that are needed for the next step.


Step 11 - Simple game

Try to make a simple, hard-coded game. Play it and give it to your friends. Test the mechanics you've implemented so far. See if the game is fun.
Change everything you need to change. Don't forget to test a lot. Always ask someone to test the game's 'fun factor', or test it yourself after a while; it's hard to notice some things right away.
This step should take a pretty long time, until you've got a playable, fun mini-game.


Step 12 - Levels

Write your level generators. Implement moving between the levels, a wilderness and/or town if you want them, saving the levels on level change if you want them to be persistent (so that they don't take up memory).
Spread your monsters and items on different depths. Add more monsters and items, with their effects, as needed.


Step 13 - Experience

Start developing your experience system and skill system. Tune the monsters' and items' stats. Make character generation screen, classes, races, and whatever else you need.
Playtest your game frequently.


Step 14 - Citizens

Add NPCs, shopkeepers, and simple quests if you need them. Keep adding features and tuning the stats.


Step 15 - Free at last

Start adding and testing all the 'unique' features you thought were so cool months (years?) ago, when you started the whole thing. Revise your opinions of them and see if they fit the game.
Write your pet random plot generator, factions system, infinite wilderness generator, neural network AI, or other unique feature, since you can now test it in a working game.


Original version submitted to rec.games.roguelike.development by Radomir 'The Sheep' Dopieralski

算24【备份】

以前写过,不过这次应该代码好看些了吧。
#!python2
from itertools import *
from operator import *
calc24 = lambda a,b,c,d:list(set(sum((
(o(p(i,q(j,k)),l)==24 and ["(%s%s(%s%s%s))%s%s"%s] or [])+
(o(i,p(q(j,k),l))==24 and ["%s%s((%s%s%s)%s%s)"%s] or [])+
(o(i,p(j,q(k,l)))==24 and ["%s%s(%s%s(%s%s%s))"%s] or [])+
(o(p(i,j),q(k,l))==24 and ["(%s%s%s)%s(%s%s%s)"%s] or [])+
(o(p(q(i,j),k),l)==24 and ["(((%s%s%s)%s%s)%s%s)"%s] or [])
for nums,opp in [((a,b,c,d),(add,sub,mul,lambda x,y:truediv(x,y) if y else float('nan')))]
for j,i,k,l in permutations(nums) for o,p,q in product(opp,repeat=3)
for r in [dict(zip(opp,("+","-","*","/")))] for s in [(i,r[o],j,r[p],k,r[q],l)]),[])))

>>> calc24(6,6,6,6)
['6+((6+6)+6)', '(((6+6)+6)+6)', '(6+(6+6))+6', '(6+6)+(6+6)', '(((6-6)-6)*6)', '(6-6)*(6+6)', '6+(6+(6+6))']
>>> calc24(2,3,8,9)
['(8/(9*3))-2', '8/(2/(9-3))', '8*(9-(2*3))', '8*((9/3)-2)', '(((9*3)/2)-8)', '(8*2)/(9-3)', '(((9/3)*8)-2)', '(9/3)-(2/8)', '(9*3)-(8/2)', '8*(9-(3*2))', '(9*(3-2))*8', '(9*(2-3))*8']

下面这个考虑了交换律的重复。故意写个很累赘的样子,
而且为了吻合IEEE还把mapcan和format等等都替换了一下。
(define (calc24 a b c d)
  (define (flat-map p x)
    (apply append (map p x)))
  (define (filter p x)
    (cond ((null? x) '())
          ((p (car x)) (cons (car x) (filter p (cdr x))))
          (else (filter p (cdr x)))))
  (define (drop-one x lst)
    (cond ((null? lst) '())
          ((equal? x (car lst)) (cdr lst))
          (else (cons (car lst) (drop-one x (cdr lst))))))
  (define (perm lst)
    (if (null? lst)
        '(())
        (flat-map
         (lambda (x)
           (map (lambda (y) (cons x y))
                (perm (drop-one x lst))))
         lst)))
  (define (pow lst n)
    (if (zero? n) '(())
        (flat-map
         (lambda (x)
           (map (lambda (y) (cons x y))
                (pow lst (- n 1))))
         lst)))
  (define (buld-exp num ops)
    (apply
     (lambda (i j k l)
       (apply
        (lambda (o p q)
          (list
           `(,o (,p ,i ,j) (,q ,k ,l))
           `(,o (,p ,i (,q ,j ,k)) ,l)))
        ops))
     num))
  (define (eval-exp exp)
    (if (list? exp)
        (let ((arg (map eval-exp (cdr exp)))
              (/ (lambda (x y)
                   (if (zero? y) +nan.0 (/ x y)))))
          (case (car exp)
            ((+) (apply + arg))
            ((-) (apply - arg))
            ((*) (apply * arg))
            ((/) (apply / arg))
            ((--) (apply - (reverse arg)))
            ((//) (apply / (reverse arg)))
            (else (error "op?"))))
        exp))
  (define (show-exp exp)
    (define (bin-op-str op arg)
      (apply (lambda (x y)
               (string-append "(" x op y ")"))
             (map (lambda (x)
                    (if (number? x) (number->string x) x)) arg)))
    (if (list? exp)
        (let ((arg (map show-exp (cdr exp)))
              (/ (lambda (x y) (if (zero? y) +nan.0 (/ x y)))))
          (case (car exp)
            ((+) (bin-op-str "+" arg))
            ((-) (bin-op-str "-" arg))
            ((*) (bin-op-str "*" arg))
            ((/) (bin-op-str "/" arg))
            ((--) (bin-op-str "-" (reverse arg)))
            ((//) (bin-op-str "/" (reverse arg)))
            (else (error "op?"))))
        exp))
  (define (unique lst)
    (if (null? lst) '()
        (cons (car lst)
              (unique
               (filter (lambda (x)
                         (not (equal? x (car lst)))) lst)))))
  (unique
   (flat-map
    (lambda (x)
      (flat-map
       (lambda (y)
         (flat-map
          (lambda (z)
            (if (= 24 (eval-exp z))
                (list (show-exp z))
                '()))
          (buld-exp x y)))
       (pow '(+ - * / -- //) 3)))
    (perm (list a b c d)))))

(calc24 2 3 8 9)
("(((9-3)/2)*8)" "(8/(2/(9-3)))" "((8/2)*(9-3))" "((9-3)/(2/8))" "((9-3)*(8/2))" "((8*(9-3))/2)" "((9-(2*3))*8)" "((9-(3*2))*8)")
(calc24 6 6 6 6)
("((6+6)+(6+6))" "((6+(6+6))+6)" "((6*6)-(6+6))" "(((6*6)-6)-6)")

更多的不同语言写的可以看这个:
http://rosettacode.org/wiki/24_game/Solve

乱如备份下平时在npp里面用来插入行首空格的东西。
能用,不过貌似可能会干出多余的事情来,比如不仅仅是行首的情况。
另外使用前务必先用一下npp自带的转义& < > "的菜单命令。
editor.pyreplace(r"^ ", r"&nbsp;")
def s():editor.pysearch(r"&nbsp; " ,lambda x,y:rp())
def rp():editor.pyreplace(r"&nbsp; ", r"&nbsp;&nbsp;") and False or s()
s()


如果要变成算24的游戏的话,还要一个随机数生成,和表达式计算的东西。

2011年11月19日星期六

存活确认

觉得blogger最近登录不便,所以这段时间有点当长文回收的地方在用了。暂且不说有多少内容,仅仅是那堆放腾起的尘埃,也够让自己呛一阵的。不过其实呢,既然这里作为一个自己感到自在的地方,也不必总太多估计。可以有一些过程中的,不成熟的,零时的,盲目的,白痴的想法也写出来。因为作为结果而言,至少是作为一个暂且还达不到的,或者没有做到的事情来说,其中的过程也是不可欠缺的。缺少了或者说完全的抛弃了愚昧的状态,却反而回避很多需要的或者说感到满足或欣喜的结果的话,失去和得到的就不是同一事物的不能层面,而是皆至于无的状态了。所以,在这里,还是来发帖确认一下成活吧。以前烦了很多傻了,以后还是会继续来犯傻,同时再多展示一些令人欣慰的事情吧。