以下是我公布的答案 (1/3)

來源: file20002000 2009-12-11 14:48:41 [] [舊帖] [給我悄悄話] 本文已被閱讀: 次 (1678 bytes)
Note. 這個思路是最直接也是最有趣的。

This is a perfect AI program! You can win the computer easily at beginning, but it becomes invulnerable later.
(You can let the computer play with itself to gain its knowledgebase.)

I have at least two other solutions, one can be as short as just a few lines. 先不貼 - 留給網上高手 (i am not a CS nor Math major)

Knowledge Database = {losing cases} ‘if I can left this case to opponent, I will win. such as (1-2-3)

Add (0-0-0) to {losing case} ‘(0-0-0) is a losing hand by game definition
Add (0-1-1) to {losing case} ‘Not Needed! I add here so you can understand my examples



SubFunction CanIWinThisHand (X-Y-Z)
Search all sub (X-Y-X)
If at least one sub(X-Y-Z) = {losing case} Then return TRUE
else return FALSE
End SubFunction




Function WhatToDoWith(A-B-C)

If (A-B-C) = {losing cases}
If A-B-C = {0-0-0} then end ‘Result 1a: Lost and Game Over and Opponent Won!
else create sub(A-B-C) randomly ‘Result 1b: Losing (such as 0-1-1)

If CanIWinThisHand (A-B-C) = TRUE ‘I can win! 0-0-5, 1-1-5 for example
Then I create that sub(A-B-C) ‘’Result 2- Wining (such as 1-1-1 -> 0-1-1)

if All CanIWinThisHand (sub(A-B-C)) =True ‘no matter what I move, my opponent may create a losing case to against me
Add (A-B-C) to my database ‘then I learned this is a new losing hand
pick randomly ‘Result 3 – Losing, but I learned from it! (Such as adding 1-2-3 to my Knowledge)

Else
pick randomly ‘Result 4 – I have no idea what this hand can be because my knowledge is no strong yet.


End Function

請您先登陸,再發跟帖!

發現Adblock插件

如要繼續瀏覽
請支持本站 請務必在本站關閉/移除任何Adblock

關閉Adblock後 請點擊

請參考如何關閉Adblock/Adblock plus

安裝Adblock plus用戶請點擊瀏覽器圖標
選擇“Disable on www.wenxuecity.com”

安裝Adblock用戶請點擊圖標
選擇“don't run on pages on this domain”