|
发表于 2011-1-30 14:27:43
|
显示全部楼层
仅供参考。
以下是我用sqlite做的部分红豆机器人的代码。请参考,也许对楼主有帮助。若需要可以qq联系。
- --------------------------------------------
- hongdou.getanswer=function()
- DatabaseOpen ("db", GetInfo(67).."hongdou2010.db", 6)
- dbp=DatabasePrepare ("db",sqlstr)
- rc = DatabaseStep ("db")
- dbinfo=DatabaseInfo("db",1)
- ---------------------------------------------------------------
- hdanswer={}
- selnum=nil
- ------------------------db.answer->hongdou.answer---------------
- ---------------------------------------------------------------
- while rc == 100 do
- db_timu=DatabaseColumnValue("db",1)
- db_answer=DatabaseColumnValue("db",2)
- comparestring(hongdou.fulltimu,db_timu)
- if same_percent==100 then
- hongdou.timsame="100%"
- hongdou.answer=db_answer
- break
- else
- hongdou.timsame=""
- comparestring(hongdou.timu,db_timu)
- hdanswer[same_percent]=db_answer
- --print(hdanswer[same_percent],db_timu,same_percent)
- end
- rc = DatabaseStep ("db")
- end
- DatabaseFinalize ("db")
- ---------------------------------------------------------------
- ---------------------------------------------------------------
- if hongdou.timsame~="100%" then
- hongdou.answer=hdanswer[table.maxn(hdanswer)]
- hongdou.timsame=table.maxn(hdanswer).."%"
- end
- ---------------------------------------------------------------
- hdanswer={}
- selnum=nil
- ---------------------------------------------------------------
- --print(hongdou.fulltimu,hongdou.answer)
- for key, value in pairs (hongdou.answertable) do
- comparestring(hongdou.answer,value)
- --print(hongdou.answer,value,same_percent)
- hdanswer[same_percent]=key
- same_percent=1
- end
- selnum=hdanswer[table.maxn(hdanswer)]
- hongdou.daansame=table.maxn(hdanswer).."%"
- --print("selnum="..selnum.."hongdou.daansame"..hongdou.daansame)
- --------------------------------------------------------------------------
- if selnum==nil then
- selnum=math.random (1,4)
- print("System AUTO random Number(1-4) is:"..selnum)
- hongdou.hasanswerstr="猜"
- else
- hongdou.hasanswerstr="库"
- end
- hongdou.answer=hongdou.answertable[selnum]
- if hongdou["answer"]~=nil then
- print("【建议答案】"..hongdou["answer"].."【选项】"..selnum)
- print("【查询方式】("..hongdou.hasanswerstr..")".."【相似度】(题目:"..hongdou.timsame..",答案:"..hongdou.daansame..")")
- hongdou.hasanswer=1
- else
- print("数据库无查询结果。入库中..")
- hongdou.hasanswer=0
- end
- Execute("answer "..selnum)
- hongdou.answer=""
- end
复制代码 |
|