~ubuntu-branches/debian/lenny/ucblogo/lenny

« back to all changes in this revision

Viewing changes to csls/poker

  • Committer: Bazaar Package Importer
  • Author(s): Hamish Moffatt
  • Date: 2001-09-02 15:15:21 UTC
  • Revision ID: james.westby@ubuntu.com-20010902151521-doo25fmfq7v3pxkg
Tags: upstream-5.1
ImportĀ upstreamĀ versionĀ 5.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
to pokerhand :cards
 
2
local [ranks suits rankarray]
 
3
poker.init :cards
 
4
if fourp [print [four of a kind] stop]
 
5
if full.housep [print [full house] stop]
 
6
if threep [print [three of a kind] stop]
 
7
if pairp [print ifelse paircount = 1 [[one pair]] [[two pairs]] stop]
 
8
if ace.highp [print ifelse flushp [[royal flush]] [[straight]] stop]
 
9
if straightp [print ifelse flushp [[straight flush]] [[straight]] stop]
 
10
if flushp [print [flush] stop]
 
11
print [nothing!]
 
12
end
 
13
 
 
14
to poker.init :cards
 
15
make "ranks map [ranknum butlast ?] :cards
 
16
make "suits remdup map "last :cards
 
17
make "rankarray {0 0 0 0 0 0 0 0 0 0 0 0 0}
 
18
foreach :ranks [setitem ? :rankarray (item ? :rankarray)+1]
 
19
end
 
20
 
 
21
to ranknum :rank
 
22
if :rank = "a [output 1]
 
23
if :rank = "j [output 11]
 
24
if :rank = "q [output 12]
 
25
if :rank = "k [output 13]
 
26
output :rank
 
27
end
 
28
 
 
29
to fourp
 
30
output memberp 4 :rankarray
 
31
end
 
32
 
 
33
to threep
 
34
output memberp 3 :rankarray
 
35
end
 
36
 
 
37
to pairp
 
38
output memberp 2 :rankarray
 
39
end
 
40
 
 
41
to full.housep
 
42
output and threep pairp
 
43
end
 
44
 
 
45
to paircount
 
46
output count locate 2 1
 
47
end
 
48
 
 
49
to locate :number :index
 
50
if :index > 13 [output []]
 
51
if (item :index :rankarray) = :number ~
 
52
   [output fput :index (locate :number :index+1)]
 
53
output locate :number :index+1
 
54
end
 
55
 
 
56
to flushp
 
57
output emptyp butfirst :suits
 
58
end
 
59
 
 
60
to straightp
 
61
output nogap (reduce "min :ranks) 5
 
62
end
 
63
 
 
64
to min :a :b
 
65
output ifelse :a < :b [:a] [:b]
 
66
end
 
67
 
 
68
to nogap :smallest :howmany
 
69
if :howmany=0 [output "true]
 
70
if not equalp (item :smallest :rankarray) 1 [output "false]
 
71
output nogap :smallest+1 :howmany-1
 
72
end
 
73
 
 
74
to ace.highp
 
75
if not equalp (item 1 :rankarray) 1 [output "false]
 
76
output nogap 10 4
 
77
end
 
78