9.26.2012

Don't always declare global variable in C/C++

If you always declare global variable instead of local,
Once you using recursive call, you may get run time error.
See

SPOJ Problem 1436: Is it a tree – PT07Y

if you move

list<int>::iterator it;
 
 from local variable to global variable, you will get run time error 
by input following:
3 2
1 3
3 2 




4.09.2012

Random Go program ~ Brown

幾天前想寫一個GTP(Go Text Protocol) base的隨機下棋程式,
不過看了一下GTP Spec. 雖然不是很複雜,但真正要寫,
也需要一些時間,所以一直沒有實際下去寫。
今天重看GTP spec. 的網站,突然發現一個叫Brown的程式,
正好符合我的需求,很快地就下載source回來看看能否Build win版…
首先用wxDevC++,開啟一個C++的console專案,
將main.cpp的內容換成brown.c的內容,並且加入剩下的檔案到專案中,
結果在Build時,有一些錯誤,
在interface.c加上#include "string.h"就OK了。
Build成exe後,發現用Panda-glGo還是不能玩,
就去下載Drago, 稍微設定一下,
It's work!

後記:
我改了一下,使Brown go可以在Panda-glGo上玩,
下載檔案及source code

8.27.2011

Python: assign list to all zero

我學python 一陣子了,但一直不知道如何一次assign給list同一個值,
之前都是用range()來assign給list的,查了一下google,但似乎沒相關的說明,
原來我要問的問題太基本了,後來終於發現,原來很簡單,
如果要assign給list a,10000個0,那就:

a = [0] * 10000

同理,如果要assign給list a,9999個1,那就:

a = [1] * 9999

7.12.2011

Renpy 與 python

renpy可以用'$'或'python:'來插入python的程式碼,
不過注意,不要用來'import' pyhon的library,
否則很容易造成 遊戲存檔失效,
如果要'import'一些額外的library,
請在'init python:'中加入即可。

7.09.2011

Renpy 6.12.1: How do I show a variable in the text?

要怎麼在對話的text中秀出變數,Renpy 官網提供以下三種方法:
$ food = "apple sauce"

"I would like to try some %(food)s, please."
"I would like to try some %s, please." % food
"I would like to try some " + food + ", please."
 不過,我在Renpy 6.12.1試的結果,目前只支援第一種:
"I would like to try some %(food)s, please."

其它兩種,不確定以前有沒有支援,目前看來是不行用的。

7.02.2011

Renpy 6.12.1: Drag and Drop

Renpy 6.12.1支援滑鼠托拉(Drag and Drop)的功能,
官網有範例,不過若直接複製貼上範例code,
會發現有些小錯誤:
1. 請將drag_group改成draggroup
2. 去下載圖片,裡面的圖記得改成自己圖片的名稱

修改後範例如下:

init python:

    def detective_dragged(drags, drop):

        if not drop:
            return

        store.detective = drags[0].drag_name
        store.city = drop.drag_name

        return True

screen send_detective_screen:

    # A map as background.
    add "europe.jpg"

    # A drag group ensures that the detectives and the cities.
    draggroup:

        # Our detectives.
        drag:
            drag_name "Ivy"
            child "ivy.png"
            droppable False
            dragged detective_dragged
            xpos 100 ypos 100
        drag:
            drag_name "Zack"
            child "zack.png"
            droppable False
            dragged detective_dragged
            xpos 150 ypos 100

        # The cities they can go to.
        drag:
            drag_name "London"
            child "london.png"
            draggable False
            xpos 450 ypos 140
        drag:
            drag_name "Paris"
            draggable False
            child "paris.png"
            xpos 500 ypos 280

label send_detective:
    "We need to investigate! Who should we send, and where should they go?"

    call screen send_detective_screen

    "Okay, we'll send %(detective)s to %(city)s."

9.08.2010

十月長工

安徽省 民歌

十月長工

正月好唱正月終,
家裏無米斗量空,
借人一担還兩担,
今年只好打長工。

二月好唱二月終,
二月初一我上工,
我子哭來妻子叫,
眼淚流了幾茶盅。

三月好唱三月終,
身背犁灣下南沖,
南頭犁到北頭轉,
一把汗珠一棵種。

四月好唱四月終,
老板的麥子黃橙橙,
從早割麥割到晚,
老板還說我不中。

五月好唱五月終,
車水拔草忙得凶,
白天做活不得閑,
夜晚抽烟不放工。

六月好唱六月終,
六月日頭熱火龍,
老板出去洋傘打,
熱火曬死我長工。

七月好唱七月終,
割罷稻子又下種,
又催收來又催種,
老板就是活閻羅。

八月好唱八月終
老板的稻場趕得凶,
稻子打了幾千石,
長工還是兩手空。

九月好唱九月終,
桂花做酒香噴噴,
老板一天三遍酒,
沒把半盅我長工。

十月好唱十月終,
十月三十我下工,
老板鷄子殺一只,
鷄頭鷄脚我長工。

老板說:
「盡你吃來盡你咽,
明年幫工我家來。」
長工說:
「你吃青草放驢屁,
明年來你家做女婿。」

其它安徽民歌:
十月唱空