source: liacs/ai/bridge/bridge.cc.tex@ 375

Last change on this file since 375 was 2, checked in by Rick van der Zwet, 15 years ago

Initial import of data of old repository ('data') worth keeping (e.g. tracking
means of URL access statistics)

File size: 37.1 KB
RevLine 
[2]1% Generator: GNU source-highlight, by Lorenzo Bettini, http://www.gnu.org/software/src-highlite
2\noindent
3\mbox{}\texttt{001:} \textit{//} \\
4\mbox{}\texttt{002:} \textit{//\ bridge.cc} \\
5\mbox{}\texttt{003:} \textit{//\ Eerste\ programmeeropgave\ voor\ AI,\ 28\ januari\ 2008,\ Bridge} \\
6\mbox{}\texttt{004:} \textit{//\ Walter\ Kosters} \\
7\mbox{}\texttt{005:} \textit{//} \\
8\mbox{}\texttt{006:} \\
9\mbox{}\texttt{007:} \textbf{\#include}\ \texttt{$<$iostream$>$} \\
10\mbox{}\texttt{008:} \textbf{\#include}\ \texttt{$<$iomanip$>$} \\
11\mbox{}\texttt{009:} \textbf{\#include}\ \texttt{$<$cstdlib$>$} \\
12\mbox{}\texttt{010:} \textbf{\#include}\ \texttt{$<$ctime$>$} \\
13\mbox{}\texttt{011:} \textbf{using}\ \textbf{namespace}\ std; \\
14\mbox{}\texttt{012:} \\
15\mbox{}\texttt{013:} \textit{/*\ Maak\ array\ verwijzingen\ expliciet\ en\ uniform\ */} \\
16\mbox{}\texttt{014:} \textbf{\#define}\ NOORD\ 0 \\
17\mbox{}\texttt{015:} \textbf{\#define}\ OOST\ \ 1 \\
18\mbox{}\texttt{016:} \textbf{\#define}\ ZUID\ \ 2 \\
19\mbox{}\texttt{017:} \textbf{\#define}\ WEST\ \ 3 \\
20\mbox{}\texttt{018:} \\
21\mbox{}\texttt{019:} \textit{/*\ Kaartdefinities\ */} \\
22\mbox{}\texttt{020:} \textbf{\#define}\ KLAVEREN\ 0 \\
23\mbox{}\texttt{021:} \textbf{\#define}\ RUITEN\ \ \ 1 \\
24\mbox{}\texttt{022:} \textbf{\#define}\ HARTEN\ \ \ 2 \\
25\mbox{}\texttt{023:} \textbf{\#define}\ SCHOPPEN\ 3 \\
26\mbox{}\texttt{024:} \\
27\mbox{}\texttt{025:} \textit{/*\ Contract\ mogelijkheden\ */} \\
28\mbox{}\texttt{026:} \textbf{\#define}\ CONTRACT$\_$RANDOM\ 0\ \textit{/*\ Agent\ EEN\ */} \\
29\mbox{}\texttt{027:} \textbf{\#define}\ CONTRACT$\_$SLIM\ 1\ \ \ \textit{/*\ Agent\ DRIE\ */} \\
30\mbox{}\texttt{028:} \\
31\mbox{}\texttt{029:} \textit{/*\ Niveau's\ */} \\
32\mbox{}\texttt{030:} \textbf{\#define}\ NIVEAU$\_$RANDOM\ 0\ \textit{/*\ Agent\ TWEE\ */} \\
33\mbox{}\texttt{031:} \textbf{\#define}\ NIVEAU$\_$SLIM\ 1\ \textit{/*\ Agent\ VIER\ */} \\
34\mbox{}\texttt{032:} \\
35\mbox{}\texttt{033:} \textit{/*\ Speeltype\ */} \\
36\mbox{}\texttt{034:} \textbf{\#define}\ SPEEL$\_$KOSTER$\_$BRIDGE\ 0 \\
37\mbox{}\texttt{035:} \\
38\mbox{}\texttt{036:} \textbf{\#define}\ VERBOSE\ 1 \\
39\mbox{}\texttt{037:} \textbf{\#define}\ SILENT\ \ 0 \\
40\mbox{}\texttt{038:} \\
41\mbox{}\texttt{039:} \textit{/*\ Afsluit\ codes,\ teveel\ is\ positief,\ teweinig\ negetief\ */} \\
42\mbox{}\texttt{040:} \textbf{\#define}\ GEHAALD\ =\ 0 \\
43\mbox{}\texttt{041:} \\
44\mbox{}\texttt{042:} \textit{//sorteer\ array\ A\ (met\ n\ elementen)\ via\ bubblesort} \\
45\mbox{}\texttt{043:} void\ \textbf{bubblesort\ }(int\ A[\ ],\ int\ n)\ \{ \\
46\mbox{}\texttt{044:} \ \ int\ i,\ j,\ temp; \\
47\mbox{}\texttt{045:} \ \ \textbf{for}\ (\ j\ =\ 1;\ j\ $<$\ n;\ j++\ ) \\
48\mbox{}\texttt{046:} \ \ \ \ \textbf{for}\ (\ i\ =\ 0;\ i\ $<$\ n-j;\ i++\ ) \\
49\mbox{}\texttt{047:} \ \ \ \ \ \ \textbf{if}\ (\ A[i]\ $>$\ A[i+1]\ )\ \{ \\
50\mbox{}\texttt{048:} \ \ \ \ \ \ \ \ temp\ =\ A[i];\ \\
51\mbox{}\texttt{049:} \ \ A[i]\ =\ A[i+1];\ \\
52\mbox{}\texttt{050:} \ \ A[i+1]\ =\ temp; \\
53\mbox{}\texttt{051:} \ \ \ \ \ \ \}\textit{//if} \\
54\mbox{}\texttt{052:} \}\textit{//bubblesort} \\
55\mbox{}\texttt{053:} \\
56\mbox{}\texttt{054:} \textit{//welke\ getalswaarde\ heeft\ kaart\ i?} \\
57\mbox{}\texttt{055:} \textit{//1..13\ zijn\ Klaver1..13,\ 14..26\ zijn\ Ruiten1..13,} \\
58\mbox{}\texttt{056:} \textit{//27..39\ zijn\ Harten1..13\ en\ 40..52\ zijn\ Schoppen1..13} \\
59\mbox{}\texttt{057:} \textit{//eigenlijk\ is\ 13\ de\ aas,\ dus\ 1\ is\ een\ 2\ ;-)} \\
60\mbox{}\texttt{058:} int\ \textbf{dewaarde\ }(int\ i)\ \{ \\
61\mbox{}\texttt{059:} \ \ \textbf{if}\ (\ i\ $<$=\ 13\ ) \\
62\mbox{}\texttt{060:} \ \ \ \ \textbf{return}\ i; \\
63\mbox{}\texttt{061:} \ \ \textbf{else}\ \textbf{if}\ (\ i\ $<$=\ 26\ ) \\
64\mbox{}\texttt{062:} \ \ \ \ \textbf{return}\ i-13; \\
65\mbox{}\texttt{063:} \ \ \textbf{else}\ \textbf{if}\ (\ i\ $<$=\ 39\ ) \\
66\mbox{}\texttt{064:} \ \ \ \ \textbf{return}\ i-26; \\
67\mbox{}\texttt{065:} \ \ \textbf{else} \\
68\mbox{}\texttt{066:} \ \ \ \ \textbf{return}\ i-39; \\
69\mbox{}\texttt{067:} \}\textit{//dewaarde} \\
70\mbox{}\texttt{068:} \\
71\mbox{}\texttt{069:} \textit{//welke\ kleurwaarde\ heeft\ kaart\ i?} \\
72\mbox{}\texttt{070:} char\ \textbf{dekleurwaarde\ }(int\ i)\ \{ \\
73\mbox{}\texttt{071:} \ \ \textbf{if}\ (\ i\ $<$=\ 13\ ) \\
74\mbox{}\texttt{072:} \ \ \ \ \textbf{return}\ KLAVEREN; \\
75\mbox{}\texttt{073:} \ \ \textbf{else}\ \textbf{if}\ (\ i\ $<$=\ 26\ ) \\
76\mbox{}\texttt{074:} \ \ \ \ \textbf{return}\ RUITEN; \\
77\mbox{}\texttt{075:} \ \ \textbf{else}\ \textbf{if}\ (\ i\ $<$=\ 39\ ) \\
78\mbox{}\texttt{076:} \ \ \ \ \textbf{return}\ HARTEN; \\
79\mbox{}\texttt{077:} \ \ \textbf{else} \\
80\mbox{}\texttt{078:} \ \ \ \ \textbf{return}\ SCHOPPEN; \\
81\mbox{}\texttt{079:} \}\textit{//dekleur} \\
82\mbox{}\texttt{080:} \\
83\mbox{}\texttt{081:} \textit{//welke\ kleur\ heeft\ kaart\ i?} \\
84\mbox{}\texttt{082:} char\ \textbf{dekleur\ }(int\ i)\ \{ \\
85\mbox{}\texttt{083:} \ \ \ \ \textbf{switch}\ (\ \textbf{dekleurwaarde\ }(i)\ )\ \{ \\
86\mbox{}\texttt{084:} \ \ \ \ \textbf{case}\ KLAVEREN: \\
87\mbox{}\texttt{085:} \ \ \ \ \ \ \ \ \textbf{return}\ \texttt{'K'}; \\
88\mbox{}\texttt{086:} \ \ \ \ \textbf{case}\ RUITEN: \\
89\mbox{}\texttt{087:} \ \ \ \ \ \ \ \ \textbf{return}\ \texttt{'R'}; \\
90\mbox{}\texttt{088:} \ \ \ \ \textbf{case}\ HARTEN: \\
91\mbox{}\texttt{089:} \ \ \ \ \ \ \ \ \textbf{return}\ \texttt{'H'}; \\
92\mbox{}\texttt{090:} \ \ \ \ \textbf{case}\ SCHOPPEN: \\
93\mbox{}\texttt{091:} \ \ \ \ \ \ \ \ \textbf{return}\ \texttt{'S'}; \\
94\mbox{}\texttt{092:} \ \ \ \ \} \\
95\mbox{}\texttt{093:} \}\textit{//dekleur} \\
96\mbox{}\texttt{094:} \\
97\mbox{}\texttt{095:} \\
98\mbox{}\texttt{096:} \textit{//print\ kaart\ i\ netjes} \\
99\mbox{}\texttt{097:} void\ \textbf{printkaart\ }(int\ i)\ \{ \\
100\mbox{}\texttt{098:} \ \ cout\ $<$$<$\ \textbf{dekleur\ }(i)\ $<$$<$\ \textbf{dewaarde\ }(i); \\
101\mbox{}\texttt{099:} \ \ \textbf{if}\ (\ \textbf{dewaarde\ }(i)\ $<$\ 10\ ) \\
102\mbox{}\texttt{100:} \ \ \ \ cout\ $<$$<$\ \texttt{"{}\ "{}}; \\
103\mbox{}\texttt{101:} \}\textit{//printkaart} \\
104\mbox{}\texttt{102:} \\
105\mbox{}\texttt{103:} \textit{//welke\ speler\ is\ i?} \\
106\mbox{}\texttt{104:} char\ \textbf{despeler\ }(int\ i)\ \{ \\
107\mbox{}\texttt{105:} \ \ \textbf{switch}\ (\ i\ )\ \{ \\
108\mbox{}\texttt{106:} \ \ \ \ \textbf{case}\ NOORD:\ \textbf{return}\ \texttt{'N'}; \\
109\mbox{}\texttt{107:} \ \ \ \ \textbf{case}\ OOST:\ \textbf{return}\ \texttt{'O'}; \\
110\mbox{}\texttt{108:} \ \ \ \ \textbf{case}\ ZUID:\ \textbf{return}\ \texttt{'Z'}; \\
111\mbox{}\texttt{109:} \ \ \ \ \textbf{case}\ WEST:\ \textbf{return}\ \texttt{'W'}; \\
112\mbox{}\texttt{110:} \ \ \}\textit{//switch} \\
113\mbox{}\texttt{111:} \ \ \textbf{return}\ \texttt{'X'}; \\
114\mbox{}\texttt{112:} \}\textit{//despeler} \\
115\mbox{}\texttt{113:} \\
116\mbox{}\texttt{114:} \textit{//===} \\
117\mbox{}\texttt{115:} \\
118\mbox{}\texttt{116:} \textbf{class}\ spel\ \{ \\
119\mbox{}\texttt{117:} \ \ \textbf{public}: \\
120\mbox{}\texttt{118:} \ \ \ \ int\ aantalkaarten;\ \ \ \ \ \textit{//hoeveel\ kaarten\ heeft\ iedere\ speler?} \\
121\mbox{}\texttt{119:} \ \ \ \ char\ troef;\ \ \ \ \ \ \ \ \ \ \ \ \textit{//KRHS} \\
122\mbox{}\texttt{120:} \ \ \ \ int\ hoogte;\ \ \ \ \ \ \ \ \ \ \ \ \textit{//1..13} \\
123\mbox{}\texttt{121:} \ \ \ \ bool\ NZ;\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textit{//true\ betekent\ NZ,\ false\ betekent\ OW} \\
124\mbox{}\texttt{122:} \ \ \ \ int\ dekaarten[4][13];\ \ \textit{//N:0,O:1,Z:2,W:3} \\
125\mbox{}\texttt{123:} \ \ \ \ int\ slagenNZ;\ \ \ \ \ \ \ \ \ \ \textit{//aantal\ slagen\ voor\ NZ} \\
126\mbox{}\texttt{124:} \ \ \ \ int\ slagenOW;\ \ \ \ \ \ \ \ \ \ \textit{//idem\ voor\ OW} \\
127\mbox{}\texttt{125:} \ \ \ \ int\ spelerniveau[3];\ \ \ \textit{/*\ Kwaliteit\ van\ speler\ */} \\
128\mbox{}\texttt{126:} \ \ \ \ void\ \textbf{schud\ }(\ ); \\
129\mbox{}\texttt{127:} \ \ \ \ void\ \textbf{print\ }(\ ); \\
130\mbox{}\texttt{128:} \ \ \ \ void\ \textbf{maakcontract\ }(int\ hoe,\ bool\ printdetails); \\
131\mbox{}\texttt{129:} \ \ \ \ void\ \textbf{afspelen\ }(int\ speeltype,\ bool\ printdetails); \\
132\mbox{}\texttt{130:} \ \ \ \ int\ \textbf{trekkaart\ }(int\ hoe,\ char\ kleur,\ int\ A[\ ],\ int\ aantal); \\
133\mbox{}\texttt{131:} \ \ \ \ int\ \textbf{uitslag\ }(bool\ printdetails); \\
134\mbox{}\texttt{132:} \};\textit{//spel} \\
135\mbox{}\texttt{133:} \\
136\mbox{}\texttt{134:} \textit{//verdeel\ de\ kaarten,\ en\ schud\ ze\ over\ de\ 4\ spelers} \\
137\mbox{}\texttt{135:} void\ spel::\textbf{schud\ }(\ )\ \{ \\
138\mbox{}\texttt{136:} \ \ int\ kaarten[52]; \\
139\mbox{}\texttt{137:} \ \ int\ i,\ j,\ temp; \\
140\mbox{}\texttt{138:} \ \ aantalkaarten\ =\ 13; \\
141\mbox{}\texttt{139:} \ \ \textbf{for}\ (\ i\ =\ 0;\ i\ $<$\ 52;\ i++\ ) \\
142\mbox{}\texttt{140:} \ \ \ \ kaarten[i]=\ i+1; \\
143\mbox{}\texttt{141:} \ \ \textbf{for}\ (\ i\ =\ 52-1;\ i\ $>$\ 0;\ i-\/-\ )\ \{ \\
144\mbox{}\texttt{142:} \ \ \ \ j\ =\ \textbf{rand\ }(\ )\ \%\ (i+1); \\
145\mbox{}\texttt{143:} \ \ \ \ temp\ =\ kaarten[i]; \\
146\mbox{}\texttt{144:} \ \ \ \ kaarten[i]\ =\ kaarten[j]; \\
147\mbox{}\texttt{145:} \ \ \ \ kaarten[j]\ =\ temp; \\
148\mbox{}\texttt{146:} \ \ \}\textit{//for} \\
149\mbox{}\texttt{147:} \ \ \textbf{for}\ (\ i\ =\ 0;\ i\ $<$\ 13;\ i++\ )\ \{ \\
150\mbox{}\texttt{148:} \ \ \ \ dekaarten[NOORD][i]\ =\ kaarten[i]; \\
151\mbox{}\texttt{149:} \ \ \ \ dekaarten[OOST][i]\ =\ kaarten[i+13]; \\
152\mbox{}\texttt{150:} \ \ \ \ dekaarten[ZUID][i]\ =\ kaarten[i+26]; \\
153\mbox{}\texttt{151:} \ \ \ \ dekaarten[WEST][i]\ =\ kaarten[i+39]; \\
154\mbox{}\texttt{152:} \ \ \}\textit{//for} \\
155\mbox{}\texttt{153:} \ \ \textbf{bubblesort\ }(dekaarten[NOORD],13); \\
156\mbox{}\texttt{154:} \ \ \textbf{bubblesort\ }(dekaarten[OOST],13); \\
157\mbox{}\texttt{155:} \ \ \textbf{bubblesort\ }(dekaarten[ZUID],13); \\
158\mbox{}\texttt{156:} \ \ \textbf{bubblesort\ }(dekaarten[WEST],13); \\
159\mbox{}\texttt{157:} \ \ slagenNZ\ =\ slagenOW\ =\ 0; \\
160\mbox{}\texttt{158:} \}\textit{//spel::schud} \\
161\mbox{}\texttt{159:} \\
162\mbox{}\texttt{160:} \textit{//print\ huidige\ kaarten} \\
163\mbox{}\texttt{161:} void\ spel::\textbf{print\ }(\ )\ \{ \\
164\mbox{}\texttt{162:} \ \ int\ i; \\
165\mbox{}\texttt{163:} \ \ cout\ $<$$<$\ \texttt{"{}=Kaart\ configuratie="{}}\ $<$$<$endl; \\
166\mbox{}\texttt{164:} \ \ cout\ $<$$<$\ endl\ $<$$<$\ \texttt{"{}Noord\ :\ "{}}; \\
167\mbox{}\texttt{165:} \ \ \textbf{for}\ (\ i\ =\ 0;\ i\ $<$\ aantalkaarten;\ i++\ )\ \{ \\
168\mbox{}\texttt{166:} \ \ \ \ \textbf{printkaart\ }(dekaarten[NOORD][i]); \\
169\mbox{}\texttt{167:} \ \ \ \ cout\ $<$$<$\ \texttt{"{}\ $|$\ "{}}; \\
170\mbox{}\texttt{168:} \ \ \}\textit{//for} \\
171\mbox{}\texttt{169:} \ \ cout\ $<$$<$\ endl; \\
172\mbox{}\texttt{170:} \ \ cout\ $<$$<$\ \texttt{"{}Oost\ \ :\ "{}}; \\
173\mbox{}\texttt{171:} \ \ \textbf{for}\ (\ i\ =\ 0;\ i\ $<$\ aantalkaarten;\ i++\ )\ \{ \\
174\mbox{}\texttt{172:} \ \ \ \ \textbf{printkaart\ }(dekaarten[OOST][i]); \\
175\mbox{}\texttt{173:} \ \ \ \ cout\ $<$$<$\ \texttt{"{}\ $|$\ "{}}; \\
176\mbox{}\texttt{174:} \ \ \}\textit{//for} \\
177\mbox{}\texttt{175:} \ \ cout\ $<$$<$\ endl; \\
178\mbox{}\texttt{176:} \ \ cout\ $<$$<$\ \texttt{"{}Zuid\ \ :\ "{}}; \\
179\mbox{}\texttt{177:} \ \ \textbf{for}\ (\ i\ =\ 0;\ i\ $<$\ aantalkaarten;\ i++\ )\ \{ \\
180\mbox{}\texttt{178:} \ \ \ \ \textbf{printkaart\ }(dekaarten[ZUID][i]); \\
181\mbox{}\texttt{179:} \ \ \ \ cout\ $<$$<$\ \texttt{"{}\ $|$\ "{}}; \\
182\mbox{}\texttt{180:} \ \ \}\textit{//for} \\
183\mbox{}\texttt{181:} \ \ cout\ $<$$<$\ endl; \\
184\mbox{}\texttt{182:} \ \ cout\ $<$$<$\ \texttt{"{}West\ \ :\ "{}}; \\
185\mbox{}\texttt{183:} \ \ \textbf{for}\ (\ i\ =\ 0;\ i\ $<$\ aantalkaarten;\ i++\ )\ \{ \\
186\mbox{}\texttt{184:} \ \ \ \ \textbf{printkaart\ }(dekaarten[WEST][i]); \\
187\mbox{}\texttt{185:} \ \ \ \ cout\ $<$$<$\ \texttt{"{}\ $|$\ "{}}; \\
188\mbox{}\texttt{186:} \ \ \}\textit{//for} \\
189\mbox{}\texttt{187:} \ \ cout\ $<$$<$\ endl; \\
190\mbox{}\texttt{188:} \}\textit{//spel::print} \\
191\mbox{}\texttt{189:} \\
192\mbox{}\texttt{190:} \textit{//maak\ een\ contract} \\
193\mbox{}\texttt{191:} void\ spel::\textbf{maakcontract\ }(int\ hoe,\ bool\ printdetails)\ \{ \\
194\mbox{}\texttt{192:} \ \ int\ spelerA,\ spelerB; \\
195\mbox{}\texttt{193:} \ \ int\ zoekpuntA,\ zoekpuntB; \\
196\mbox{}\texttt{194:} \ \ int\ slagen; \\
197\mbox{}\texttt{195:} \ \ int\ kleurAantal[]\ =\ \{0,\ 0,\ 0,\ 0\}; \\
198\mbox{}\texttt{196:} \\
199\mbox{}\texttt{197:} \ \ \textit{/*\ Speler\ volledig\ random\ */} \\
200\mbox{}\texttt{198:} \ \ NZ\ =\ (\ \textbf{rand\ }(\ )\ \%\ 2\ ==\ 1\ ); \\
201\mbox{}\texttt{199:} \\
202\mbox{}\texttt{200:} \ \ \textbf{switch}\ (hoe)\ \{ \\
203\mbox{}\texttt{201:} \ \ \textbf{case}\ CONTRACT$\_$RANDOM: \\
204\mbox{}\texttt{202:} \ \ \ \ troef\ =\ \textbf{dekleur\ }(\textbf{rand\ }(\ )\ \%\ 52); \\
205\mbox{}\texttt{203:} \ \ \ \ hoogte\ =\ 1\ +\ \textbf{rand\ }(\ )\ \%\ 13; \\
206\mbox{}\texttt{204:} \ \ \ \ \textbf{break}; \\
207\mbox{}\texttt{205:} \ \ \textbf{case}\ CONTRACT$\_$SLIM: \\
208\mbox{}\texttt{206:} \ \ \ \ \textit{/*\ Variable\ om\ de\ juiste\ array\ rijen\ te\ selecteren\ */} \\
209\mbox{}\texttt{207:} \ \ \ \ \textbf{if}\ (\ NZ\ )\ \{ \\
210\mbox{}\texttt{208:} \ \ \ \ \ \ \ \ spelerA\ =\ NOORD; \\
211\mbox{}\texttt{209:} \ \ \ \ \ \ \ \ spelerB\ =\ ZUID; \\
212\mbox{}\texttt{210:} \ \ \ \ \}\ \textbf{else}\ \{ \\
213\mbox{}\texttt{211:} \ \ \ \ \ \ \ \ spelerA\ =\ OOST; \\
214\mbox{}\texttt{212:} \ \ \ \ \ \ \ \ spelerB\ =\ WEST; \\
215\mbox{}\texttt{213:} \ \ \ \ \} \\
216\mbox{}\texttt{214:} \\
217\mbox{}\texttt{215:} \ \ \ \ \textit{/*\ Bepaal\ aantal\ kaarten\ per\ kleur\ */} \\
218\mbox{}\texttt{216:} \ \ \ \ \textbf{for}\ (\ int\ i\ =\ 0;\ i\ $<$\ 13;\ i++\ )\ \{ \\
219\mbox{}\texttt{217:} \ \ \ \ \ \ \ \ kleurAantal[\textbf{dekleurwaarde\ }(dekaarten[spelerA][i])]++; \\
220\mbox{}\texttt{218:} \ \ \ \ \ \ \ \ kleurAantal[\textbf{dekleurwaarde\ }(dekaarten[spelerB][i])]++; \\
221\mbox{}\texttt{219:} \ \ \ \ \} \\
222\mbox{}\texttt{220:} \\
223\mbox{}\texttt{221:} \ \ \ \ \textit{/*\ Troef\ is\ de\ meeste\ kaarten\ in\ handen\ */} \\
224\mbox{}\texttt{222:} \ \ \ \ troef\ =\ 0; \\
225\mbox{}\texttt{223:} \ \ \ \ \textbf{for}\ (\ int\ i\ =\ 1;\ i\ $<$\ 4;\ i++\ ) \\
226\mbox{}\texttt{224:} \ \ \ \ \ \ \ \ \textbf{if}\ (\ kleurAantal[i]\ $>$\ kleurAantal[i\ -\ 1]\ ) \\
227\mbox{}\texttt{225:} \ \ \ \ \ \ \ \ \ \ \ \ troef\ =\ i; \\
228\mbox{}\texttt{226:} \\
229\mbox{}\texttt{227:} \ \ \ \ \textit{/*\ Elke\ troef\ levert\ een\ slag\ op\ */} \\
230\mbox{}\texttt{228:} \ \ \ \ hoogte\ =\ kleurAantal[troef]; \\
231\mbox{}\texttt{229:} \\
232\mbox{}\texttt{230:} \ \ \ \ \textit{/*\ Hoogste\ kaart(en)\ leveren\ ook\ slagen\ op\ */} \\
233\mbox{}\texttt{231:} \ \ \ \ slagen\ =\ 0; \\
234\mbox{}\texttt{232:} \ \ \ \ \textit{/*\ i\ is\ de\ zoekkaart\ */} \\
235\mbox{}\texttt{233:} \ \ \ \ \textbf{for}\ (int\ i\ =\ 52;\ i\ $>$=\ 0;)\ \{ \\
236\mbox{}\texttt{234:} \ \ \ \ \ \ \ \ \textbf{while}\ (zoekpuntA\ !=\ -1\ \&\&\ dekaarten[spelerA][zoekpuntA]\ $>$\ i) \\
237\mbox{}\texttt{235:} \ \ \ \ \ \ \ \ \ \ \ \ zoekpuntA-\/-; \\
238\mbox{}\texttt{236:} \ \ \ \ \ \ \ \ \textbf{while}\ (zoekpuntB\ !=\ -1\ \&\&\ dekaarten[spelerB][zoekpuntB]\ $>$\ i) \\
239\mbox{}\texttt{237:} \ \ \ \ \ \ \ \ \ \ \ \ zoekpuntB-\/-; \\
240\mbox{}\texttt{238:} \\
241\mbox{}\texttt{239:} \ \ \ \ \ \ \ \ \textit{/*\ Hebben\ we\ de\ kaart\ in\ bezit\ of\ moeten\ we\ naar\ een\ aas\ van} \\
242\mbox{}\texttt{240:} \textit{\ \ \ \ \ \ \ \ \ *\ een\ andere\ kleur\ gaan\ zoeken\ */} \\
243\mbox{}\texttt{241:} \ \ \ \ \ \ \ \ \textbf{if}\ (zoekpuntA\ ==\ -1\ \&\&\ zoekpuntB\ ==\ -1)\ \{ \\
244\mbox{}\texttt{242:} \ \ \ \ \ \ \ \ \ \ \ \ \textbf{break}; \\
245\mbox{}\texttt{243:} \ \ \ \ \ \ \ \ \}\ \textbf{else}\ \textbf{if}\ (zoekpuntA\ !=\ -1\ \&\&\ dekaarten[spelerA][zoekpuntA]\ ==\ i)\ \{ \\
246\mbox{}\texttt{244:} \ \ \ \ \ \ \ \ \ \ \ \ slagen++; \\
247\mbox{}\texttt{245:} \ \ \ \ \ \ \ \ \ \ \ \ i-\/-; \\
248\mbox{}\texttt{246:} \ \ \ \ \ \ \ \ \}\ \textbf{else}\ \textbf{if}\ (zoekpuntB\ !=\ -1\ \&\&\ dekaarten[spelerB][zoekpuntB]\ ==\ i)\ \{ \\
249\mbox{}\texttt{247:} \ \ \ \ \ \ \ \ \ \ \ \ slagen++; \\
250\mbox{}\texttt{248:} \ \ \ \ \ \ \ \ \ \ \ \ i-\/-; \\
251\mbox{}\texttt{249:} \ \ \ \ \ \ \ \ \}\ \textbf{else}\ \{ \\
252\mbox{}\texttt{250:} \ \ \ \ \ \ \ \ \ \ \ \ \textbf{if}\ (\ i\ $<$=\ 13\ )\ \{ \\
253\mbox{}\texttt{251:} \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textit{/*\ KLAVEREN\ aas\ is\ niet\ in\ bezit\ */} \\
254\mbox{}\texttt{252:} \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textbf{break}; \\
255\mbox{}\texttt{253:} \ \ \ \ \ \ \ \ \ \ \ \ \}\ \textbf{else}\ \{ \\
256\mbox{}\texttt{254:} \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textit{/*\ Spring\ naar\ de\ volgende\ aas\ */} \\
257\mbox{}\texttt{255:} \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textbf{if}\ ((i\ \%\ 13)\ ==\ 0) \\
258\mbox{}\texttt{256:} \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ i\ =\ i\ -\ 13; \\
259\mbox{}\texttt{257:} \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textbf{else} \\
260\mbox{}\texttt{258:} \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ i\ =\ i\ -\ (i\ \%\ 13); \\
261\mbox{}\texttt{259:} \ \ \ \ \ \ \ \ \ \ \ \ \} \\
262\mbox{}\texttt{260:} \ \ \ \ \ \ \ \ \} \\
263\mbox{}\texttt{261:} \ \ \ \ \} \\
264\mbox{}\texttt{262:} \ \ \ \ hoogte\ =\ hoogte\ +\ slagen; \\
265\mbox{}\texttt{263:} \\
266\mbox{}\texttt{264:} \ \ \ \ \textit{/*\ Set\ troef\ naar\ ASCII\ waarde\ om\ */} \\
267\mbox{}\texttt{265:} \ \ \ \ troef\ =\ \textbf{dekleur\ }(\ (troef\ +\ 1)\ *\ 13); \\
268\mbox{}\texttt{266:} \ \ \ \ \textbf{break}; \\
269\mbox{}\texttt{267:} \ \ \} \\
270\mbox{}\texttt{268:} \\
271\mbox{}\texttt{269:} \ \ \textbf{if}\ (printdetails)\ \{ \\
272\mbox{}\texttt{270:} \ \ \ \ cout\ $<$$<$\ endl\ $<$$<$\ \texttt{"{}=Contract="{}}\ $<$$<$\ endl; \\
273\mbox{}\texttt{271:} \ \ \ \ cout\ $<$$<$\ \texttt{"{}Paar\ \ \ :\ "{}}\ $<$$<$\ (\ NZ\ ?\ \texttt{"{}NZ\ "{}}\ :\ \texttt{"{}OW\ "{}}\ )\ $<$$<$\ endl; \\
274\mbox{}\texttt{272:} \ \ \ \ cout\ $<$$<$\ \texttt{"{}Slagen\ :\ "{}}\ $<$$<$\ hoogte\ $<$$<$endl; \\
275\mbox{}\texttt{273:} \ \ \ \ cout\ $<$$<$\ \texttt{"{}Troef\ \ :\ "{}}\ $<$$<$\ troef\ $<$$<$\ endl\ $<$$<$\ endl; \\
276\mbox{}\texttt{274:} \ \ \} \\
277\mbox{}\texttt{275:} \}\textit{//spel::maakcontract} \\
278\mbox{}\texttt{276:} \\
279\mbox{}\texttt{277:} \textit{//trek\ een\ random\ kaart\ uit\ A\ (die\ er\ aantal\ heeft)} \\
280\mbox{}\texttt{278:} \textit{//voorkeur\ voor\ kleur,\ anders\ random} \\
281\mbox{}\texttt{279:} int\ spel::\textbf{trekkaart\ }(int\ hoe,\ char\ kleur,\ int\ A[\ ],\ int\ aantal)\ \{ \\
282\mbox{}\texttt{280:} \ \ int\ j,\ i\ =\ \textbf{rand\ }(\ )\ \%\ aantal,\ vanaf,\ totenmet,\ dekaart; \\
283\mbox{}\texttt{281:} \ \ int\ hoogstekaart\ =\ 0; \\
284\mbox{}\texttt{282:} \ \ bool\ heeftkleur\ =\ \textbf{false}; \\
285\mbox{}\texttt{283:} \\
286\mbox{}\texttt{284:} \ \ \textit{/*\ Bepaal\ of\ gevraagde\ kleur\ in\ bezit\ is\ */} \\
287\mbox{}\texttt{285:} \ \ \textbf{for}\ (\ j\ =\ 0;\ j\ $<$\ aantal;\ j++\ )\ \{ \\
288\mbox{}\texttt{286:} \ \ \ \ \textbf{if}\ (\ \textbf{dekleur\ }(A[j])\ ==\ kleur\ )\ \{ \\
289\mbox{}\texttt{287:} \ \ \ \ \ \ \textbf{if}\ (\ heeftkleur\ ) \\
290\mbox{}\texttt{288:} \ \ \ \ \ \ \ \ totenmet\ =\ j; \\
291\mbox{}\texttt{289:} \ \ \ \ \ \ \textbf{else} \\
292\mbox{}\texttt{290:} \ \ \ \ \ \ \ \ totenmet\ =\ vanaf\ =\ j; \\
293\mbox{}\texttt{291:} \ \ \ \ \ \ heeftkleur\ =\ \textbf{true}; \\
294\mbox{}\texttt{292:} \ \ \ \ \}\textit{//if} \\
295\mbox{}\texttt{293:} \ \ \}\textit{//for} \\
296\mbox{}\texttt{294:} \\
297\mbox{}\texttt{295:} \ \ \textbf{switch}\ (hoe)\ \{ \\
298\mbox{}\texttt{296:} \ \ \textbf{case}\ NIVEAU$\_$RANDOM: \\
299\mbox{}\texttt{297:} \ \ \ \ \textbf{if}\ (\ heeftkleur\ ) \\
300\mbox{}\texttt{298:} \ \ \ \ \ \ i\ =\ vanaf\ +\ \textbf{rand\ }(\ )\ \%\ (\ totenmet\ -\ vanaf\ +\ 1\ ); \\
301\mbox{}\texttt{299:} \ \ \ \ \textbf{break}; \\
302\mbox{}\texttt{300:} \ \ \textbf{case}\ NIVEAU$\_$SLIM: \\
303\mbox{}\texttt{301:} \ \ \ \ \textit{/*\ Als\ eerste\ kiezen,\ levert\ bepaalde\ privileges\ */} \\
304\mbox{}\texttt{302:} \ \ \ \ \textbf{if}\ (\ kleur\ ==\ \texttt{'X'}\ )\ \{ \\
305\mbox{}\texttt{303:} \ \ \ \ \ \ \ \ \textit{/*\ bepalen\ beste\ kaart,\ hoogste\ troef,\ dan\ hoogste\ andere\ kaart\ */} \\
306\mbox{}\texttt{304:} \ \ \ \ \ \ \ \ \textbf{for}\ (\ j\ =\ 1;\ j\ $<$\ aantal;\ j++\ )\ \{ \\
307\mbox{}\texttt{305:} \ \ \ \ \ \ \ \ \ \ \ \ \textbf{if}\ (\ \textbf{dewaarde\ }(A[j])\ \ $>$\ \textbf{dewaarde\ }(hoogstekaart)\ )\ \{ \\
308\mbox{}\texttt{306:} \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ hoogstekaart\ =\ j; \\
309\mbox{}\texttt{307:} \ \ \ \ \ \ \ \ \ \ \ \ \}\ \textbf{else}\ \textbf{if}\ (\ \textbf{dewaarde\ }(A[j])\ ==\ \textbf{dewaarde\ }(hoogstekaart)\ )\ \{ \\
310\mbox{}\texttt{308:} \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textit{/*\ Troef\ is\ beter\ */} \\
311\mbox{}\texttt{309:} \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textbf{if}\ (\ \textbf{dekleur\ }(A[j])\ ==\ troef\ )\ \{ \\
312\mbox{}\texttt{310:} \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ hoogstekaart\ =\ j; \\
313\mbox{}\texttt{311:} \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \} \\
314\mbox{}\texttt{312:} \ \ \ \ \ \ \ \ \ \ \ \ \} \\
315\mbox{}\texttt{313:} \ \ \ \ \ \ \ \ \} \\
316\mbox{}\texttt{314:} \ \ \ \ \ \ \ \ i\ =\ hoogstekaart; \\
317\mbox{}\texttt{315:} \ \ \ \ \ \ \ \ \textbf{break}; \\
318\mbox{}\texttt{316:} \ \ \ \ \} \\
319\mbox{}\texttt{317:} \\
320\mbox{}\texttt{318:} \ \ \ \ \textit{/*\ Troef\ spelen,\ levert\ aparte\ regels\ */} \\
321\mbox{}\texttt{319:} \ \ \ \ \textbf{if}\ (\ kleur\ ==\ troef\ )\ \{ \\
322\mbox{}\texttt{320:} \ \ \ \ \ \ \ \ \textit{/*\ Hoogste\ troef\ als\ present,\ anders\ laagste\ kaart\ */} \\
323\mbox{}\texttt{321:} \ \ \ \ \ \ \ \ \textbf{if}\ (\ heeftkleur\ ) \\
324\mbox{}\texttt{322:} \ \ \ \ \ \ \ \ \ \ \ \ i\ =\ totenmet; \\
325\mbox{}\texttt{323:} \ \ \ \ \ \ \ \ \textbf{else} \\
326\mbox{}\texttt{324:} \ \ \ \ \ \ \ \ \ \ \ \ i\ =\ 0; \\
327\mbox{}\texttt{325:} \ \ \ \ \ \ \ \ \textbf{break}; \\
328\mbox{}\texttt{326:} \ \ \ \ \} \\
329\mbox{}\texttt{327:} \\
330\mbox{}\texttt{328:} \ \ \ \ \textit{/*\ Als\ kleur\ present\ dan\ meespelen\ met\ hoogste\ kaart\ */} \\
331\mbox{}\texttt{329:} \ \ \ \ \textbf{if}\ (\ heeftkleur\ )\ \{ \\
332\mbox{}\texttt{330:} \ \ \ \ \ \ \ \ i\ =\ totenmet; \\
333\mbox{}\texttt{331:} \ \ \ \ \ \ \ \ \textbf{break}; \\
334\mbox{}\texttt{332:} \ \ \ \ \} \\
335\mbox{}\texttt{333:} \\
336\mbox{}\texttt{334:} \ \ \ \ \textit{/*\ Bij\ ontbreken\ van\ kleur,\ bepaal\ of\ troef\ present\ is\ \ */} \\
337\mbox{}\texttt{335:} \ \ \ \ \textbf{for}\ (\ j\ =\ 0;\ j\ $<$\ aantal;\ j++\ ) \\
338\mbox{}\texttt{336:} \ \ \ \ \ \ \textbf{if}\ (\ \textbf{dekleur\ }(A[j])\ ==\ troef\ )\ \{ \\
339\mbox{}\texttt{337:} \ \ \ \ \ \ \ \ \textbf{if}\ (\ heeftkleur\ ) \\
340\mbox{}\texttt{338:} \ \ \ \ \ \ \ \ \ \ totenmet\ =\ j; \\
341\mbox{}\texttt{339:} \ \ \ \ \ \ \ \ \textbf{else} \\
342\mbox{}\texttt{340:} \ \ \ \ \ \ \ \ \ \ totenmet\ =\ vanaf\ =\ j; \\
343\mbox{}\texttt{341:} \ \ \ \ \ \ \ \ heeftkleur\ =\ \textbf{true}; \\
344\mbox{}\texttt{342:} \ \ \ \ \ \ \}\textit{//if} \\
345\mbox{}\texttt{343:} \ \ \ \ \textit{/*\ 'Steel'\ het\ slag\ door\ kleinste\ troefje\ te\ spelen\ */} \\
346\mbox{}\texttt{344:} \ \ \ \ \textbf{if}\ (\ heeftkleur\ )\ \{ \\
347\mbox{}\texttt{345:} \ \ \ \ \ \ \ \ i\ =\ vanaf; \\
348\mbox{}\texttt{346:} \ \ \ \ \ \ \ \ \textbf{break}; \\
349\mbox{}\texttt{347:} \ \ \ \ \} \\
350\mbox{}\texttt{348:} \\
351\mbox{}\texttt{349:} \ \ \ \ \textit{/*\ Niets\ kunnen\ betekenen\ hier,\ laagste\ kaart\ dan\ maar\ ;-)\ */} \\
352\mbox{}\texttt{350:} \ \ \ \ i\ =\ 0; \\
353\mbox{}\texttt{351:} \ \ \ \ \textbf{break}; \\
354\mbox{}\texttt{352:} \ \ \} \\
355\mbox{}\texttt{353:} \\
356\mbox{}\texttt{354:} \ \ \textit{/*\ Doe\ de\ boekhouding\ en\ werk\ het\ de\ eigen\ hand\ bij\ */} \\
357\mbox{}\texttt{355:} \ \ dekaart\ =\ A[i]; \\
358\mbox{}\texttt{356:} \ \ \textbf{for}\ (\ j\ =\ i;\ j\ $<$\ aantal-1;\ j++\ ) \\
359\mbox{}\texttt{357:} \ \ \ \ A[j]\ =\ A[j+1]; \\
360\mbox{}\texttt{358:} \ \ A[aantal-1]\ =\ 0; \\
361\mbox{}\texttt{359:} \ \ \textbf{return}\ dekaart; \\
362\mbox{}\texttt{360:} \}\textit{//spel::trekkaart} \\
363\mbox{}\texttt{361:} \\
364\mbox{}\texttt{362:} \textit{//speel\ af;\ printdetails\ geeft\ meer\ informatie} \\
365\mbox{}\texttt{363:} void\ spel::\textbf{afspelen\ }(int\ speeltype,\ bool\ printdetails)\ \{ \\
366\mbox{}\texttt{364:} \ \ int\ speler,\ winnaar,\ hoogste,\ winkleur,\ vraagkleur; \\
367\mbox{}\texttt{365:} \ \ int\ kaart[\ ]\ =\ \{0,\ 0,\ 0,\ 0\}; \\
368\mbox{}\texttt{366:} \ \ int\ buurt\ =\ 1; \\
369\mbox{}\texttt{367:} \\
370\mbox{}\texttt{368:} \ \ \textit{/*\ Laat\ random\ speler\ \ beginnen\ */} \\
371\mbox{}\texttt{369:} \ \ speler\ =\ \textbf{rand\ }(\ )\ \%\ 4;\ \textit{//\ 0123} \\
372\mbox{}\texttt{370:} \\
373\mbox{}\texttt{371:} \ \ \textbf{if}\ (printdetails)\ \{ \\
374\mbox{}\texttt{372:} \ \ \ \ cout\ $<$$<$\ \texttt{"{}=Spel="{}}\ $<$$<$endl; \\
375\mbox{}\texttt{373:} \ \ \ \ cout\ $<$$<$\ \texttt{"{}S\ =\ Speelt,\ Kx\ =\ Kaart\ x"{}}\ $<$$<$\ endl; \\
376\mbox{}\texttt{374:} \ \ \ \ cout\ $<$$<$\ \texttt{"{}Noord\ -$>$\ Oost\ -$>$\ Zuid\ -$>$\ West\ -$>$\ Noord\ -\/-$>$\ Oost\ -$>$\ Zuid"{}}\ $<$$<$endl; \\
377\mbox{}\texttt{375:} \ \ \ \ cout\ $<$$<$\ \texttt{"{}Buurt\ $|$\ S\ $|$\ K1\ \ $|$\ K2\ \ $|$\ K3\ \ $|$\ K4\ \ $|$\ Winnaar\ $|$"{}}\ $<$$<$\ endl; \\
378\mbox{}\texttt{376:} \ \ \ \ cout\ $<$$<$\ \texttt{"{}-\/-\/--\/-\/-$|$-\/-\/-$|$-\/-\/--\/-$|$-\/-\/--\/-$|$-\/-\/--\/-$|$-\/-\/--\/-$|$-\/-\/--\/-\/--\/-\/-$|$"{}}\ $<$$<$\ endl; \\
379\mbox{}\texttt{377:} \ \ \} \\
380\mbox{}\texttt{378:} \\
381\mbox{}\texttt{379:} \ \ \textbf{switch}\ (speeltype)\ \{ \\
382\mbox{}\texttt{380:} \ \ \textbf{case}\ SPEEL$\_$KOSTER$\_$BRIDGE: \\
383\mbox{}\texttt{381:} \ \ \ \ \textbf{while}\ (\ aantalkaarten\ $>$\ 0\ )\ \{ \\
384\mbox{}\texttt{382:} \ \ \ \ \ \ \textbf{if}\ (printdetails)\ \{ \\
385\mbox{}\texttt{383:} \ \ \ \ \ \ \ \ \textbf{if}\ (\ buurt\ $<$\ 10\ ) \\
386\mbox{}\texttt{384:} \ \ \ \ \ \ \ \ \ \ cout\ $<$$<$\ \texttt{"{}\ "{}}; \\
387\mbox{}\texttt{385:} \ \ \ \ \ \ \ \ cout\ $<$$<$\ buurt\ $<$$<$\ \texttt{"{}\ \ \ \ $|$\ "{}}; \\
388\mbox{}\texttt{386:} \ \ \ \ \ \ \} \\
389\mbox{}\texttt{387:} \\
390\mbox{}\texttt{388:} \ \ \ \ \ \ \textit{/*\ Initiele\ kaart,\ geen\ voorkeur\ voor\ kleur\ */} \\
391\mbox{}\texttt{389:} \ \ \ \ \ \ kaart[0]\ =\ \textbf{trekkaart\ }(spelerniveau[speler],\texttt{'X'},dekaarten[speler], \\
392\mbox{}\texttt{390:} \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ aantalkaarten); \\
393\mbox{}\texttt{391:} \ \ \ \ \ \ vraagkleur\ =\ \textbf{dekleur\ }(kaart[0]); \\
394\mbox{}\texttt{392:} \ \ \ \ \ \ \textbf{if}\ (\ printdetails\ )\ \{ \\
395\mbox{}\texttt{393:} \ \ \ \ \ \ \ \ cout\ $<$$<$\ \textbf{despeler\ }(speler)\ $<$$<$\ \texttt{"{}\ $|$\ "{}}; \\
396\mbox{}\texttt{394:} \ \ \ \ \ \ \ \ \textbf{printkaart\ }(kaart[0]); \\
397\mbox{}\texttt{395:} \ \ \ \ \ \ \ \ cout\ $<$$<$\ \texttt{"{}\ $|$\ "{}}; \\
398\mbox{}\texttt{396:} \ \ \ \ \ \ \}\textit{//if} \\
399\mbox{}\texttt{397:} \\
400\mbox{}\texttt{398:} \ \ \ \ \ \ \textit{/*\ Laat\ de\ rest\ bijspelen\ */} \\
401\mbox{}\texttt{399:} \ \ \ \ \ \ \textbf{for}\ (int\ i\ =\ 1;\ i\ $<$=\ 3;\ i++)\ \{ \\
402\mbox{}\texttt{400:} \ \ \ \ \ \ \ \ kaart[i]\ =\ \textbf{trekkaart\ }(spelerniveau[i],\ vraagkleur, \\
403\mbox{}\texttt{401:} \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ dekaarten[(speler+i)\%4],aantalkaarten); \\
404\mbox{}\texttt{402:} \ \ \ \ \ \ \ \ \textbf{if}\ (\ printdetails\ )\ \{ \\
405\mbox{}\texttt{403:} \ \ \ \ \ \ \ \ \ \ \textbf{printkaart\ }(kaart[i]); \\
406\mbox{}\texttt{404:} \ \ \ \ \ \ \ \ \ \ cout\ $<$$<$\ \texttt{"{}\ $|$\ "{}}; \\
407\mbox{}\texttt{405:} \ \ \ \ \ \ \ \ \}\textit{//if} \\
408\mbox{}\texttt{406:} \ \ \ \ \ \ \} \\
409\mbox{}\texttt{407:} \\
410\mbox{}\texttt{408:} \ \ \ \ \ \ aantalkaarten-\/-; \\
411\mbox{}\texttt{409:} \\
412\mbox{}\texttt{410:} \ \ \ \ \ \ \textit{/*\ controleer\ troef\ in\ het\ spel\ */} \\
413\mbox{}\texttt{411:} \ \ \ \ \ \ \textbf{if}\ (\ \textbf{dekleur}(kaart[0])\ ==\ troef\ $|$$|$\ \textbf{dekleur}(kaart[1])\ ==\ troef\ \\
414\mbox{}\texttt{412:} \ \ \ \ \ \ \ \ \ \ \ $|$$|$\ \textbf{dekleur}(kaart[2])\ ==\ troef\ $|$$|$\ \textbf{dekleur}(kaart[3])\ ==\ troef\ ) \\
415\mbox{}\texttt{413:} \ \ \ \ \ \ winkleur\ =\ troef; \\
416\mbox{}\texttt{414:} \ \ \ \ \ \ \textbf{else} \\
417\mbox{}\texttt{415:} \ \ \ \ \ \ \ \ winkleur\ =\ \textbf{dekleur\ }(kaart[0]); \\
418\mbox{}\texttt{416:} \\
419\mbox{}\texttt{417:} \ \ \ \ \ \ \textit{/*\ bepaal\ de\ winnende\ spelers\ */} \\
420\mbox{}\texttt{418:} \ \ \ \ \ \ hoogste\ =\ -1; \\
421\mbox{}\texttt{419:} \ \ \ \ \ \ \textbf{if}\ (\ \textbf{dekleur\ }(kaart[0])\ ==\ winkleur\ \&\&\ kaart[0]\ $>$\ hoogste\ )\ \{ \\
422\mbox{}\texttt{420:} \ \ \ \ \ \ \ \ winnaar\ =\ speler; \\
423\mbox{}\texttt{421:} \ \ \ \ \ \ \ \ hoogste\ =\ kaart[0]; \\
424\mbox{}\texttt{422:} \ \ \ \ \ \ \}\textit{//if} \\
425\mbox{}\texttt{423:} \ \ \ \ \ \ \textbf{if}\ (\ \textbf{dekleur\ }(kaart[1])\ ==\ winkleur\ \&\&\ kaart[1]\ $>$\ hoogste\ )\ \{ \\
426\mbox{}\texttt{424:} \ \ \ \ \ \ \ \ winnaar\ =\ (speler+1)\ \%\ 4; \\
427\mbox{}\texttt{425:} \ \ \ \ \ \ \ \ hoogste\ =\ kaart[1]; \\
428\mbox{}\texttt{426:} \ \ \ \ \ \ \}\textit{//if} \\
429\mbox{}\texttt{427:} \ \ \ \ \ \ \textbf{if}\ (\ \textbf{dekleur\ }(kaart[2])\ ==\ winkleur\ \&\&\ kaart[2]\ $>$\ hoogste\ )\ \{ \\
430\mbox{}\texttt{428:} \ \ \ \ \ \ \ \ winnaar\ =\ (speler+2)\ \%\ 4; \\
431\mbox{}\texttt{429:} \ \ \ \ \ \ \ \ hoogste\ =\ kaart[2]; \\
432\mbox{}\texttt{430:} \ \ \ \ \ \ \}\textit{//if} \\
433\mbox{}\texttt{431:} \ \ \ \ \ \ \textbf{if}\ (\ \textbf{dekleur\ }(kaart[3])\ ==\ winkleur\ \&\&\ kaart[3]\ $>$\ hoogste\ )\ \{ \\
434\mbox{}\texttt{432:} \ \ \ \ \ \ \ \ winnaar\ =\ (speler+3)\ \%\ 4; \\
435\mbox{}\texttt{433:} \ \ \ \ \ \ \ \ hoogste\ =\ kaart[3]; \\
436\mbox{}\texttt{434:} \ \ \ \ \ \ \}\textit{//if} \\
437\mbox{}\texttt{435:} \\
438\mbox{}\texttt{436:} \ \ \ \ \ \ \textbf{if}\ (\ printdetails\ )\ \{ \\
439\mbox{}\texttt{437:} \ \ \ \ \ \ \ \ cout\ $<$$<$\ \textbf{despeler\ }(winnaar)\ $<$$<$\ \texttt{"{}\ \ \ \ \ \ \ $|$"{}}\ $<$$<$\ endl; \\
440\mbox{}\texttt{438:} \ \ \ \ \ \ \}\textit{//if} \\
441\mbox{}\texttt{439:} \ \ \ \ \ \ \textbf{if}\ (\ winnaar\ ==\ 0\ $|$$|$\ winnaar\ ==\ 2\ ) \\
442\mbox{}\texttt{440:} \ \ \ \ \ \ \ \ slagenNZ++; \\
443\mbox{}\texttt{441:} \ \ \ \ \ \ \textbf{else} \\
444\mbox{}\texttt{442:} \ \ \ \ \ \ \ \ slagenOW++; \\
445\mbox{}\texttt{443:} \ \ \ \ \ \ speler\ =\ winnaar; \\
446\mbox{}\texttt{444:} \\
447\mbox{}\texttt{445:} \ \ \ \ \ \ buurt++; \\
448\mbox{}\texttt{446:} \ \ \ \ \}\textit{//while} \\
449\mbox{}\texttt{447:} \ \ \ \ \textbf{break}; \\
450\mbox{}\texttt{448:} \ \ \}\textit{//switch} \\
451\mbox{}\texttt{449:} \}\textit{//spel::afspelen} \\
452\mbox{}\texttt{450:} \\
453\mbox{}\texttt{451:} \textit{//uitslag\ op\ scherm} \\
454\mbox{}\texttt{452:} int\ spel::\textbf{uitslag\ }(bool\ printdetails)\ \{ \\
455\mbox{}\texttt{453:} \ \ int\ slagen\ =\ (\ NZ\ ?\ slagenNZ\ :\ slagenOW); \\
456\mbox{}\texttt{454:} \ \ \textbf{if}\ (printdetails)\ \{ \\
457\mbox{}\texttt{455:} \ \ \ \ cout\ $<$$<$\ \texttt{"{}=Uitslag="{}}\ $<$$<$\ endl; \\
458\mbox{}\texttt{456:} \ \ \ \ cout\ $<$$<$\ \texttt{"{}Slagen\ NZ\ \ \ \ \ \ \ :\ "{}}\ $<$$<$\ slagenNZ\ $<$$<$\ endl; \\
459\mbox{}\texttt{457:} \ \ \ \ cout\ $<$$<$\ \texttt{"{}Slagen\ OW\ \ \ \ \ \ \ :\ "{}}\ $<$$<$\ slagenOW\ $<$$<$\ endl; \\
460\mbox{}\texttt{458:} \ \ \ \ cout\ $<$$<$\ \texttt{"{}Contract\ bod\ \ \ \ :\ "{}}\ $<$$<$\ hoogte\ $<$$<$\ endl; \\
461\mbox{}\texttt{459:} \ \ \ \ cout\ $<$$<$\ \texttt{"{}Contract\ paar\ \ \ :\ "{}}\ $<$$<$\ (\ NZ\ ?\ \texttt{"{}NZ\ "{}}\ :\ \texttt{"{}OW\ "{}}\ )\ $<$$<$\ endl; \\
462\mbox{}\texttt{460:} \ \ \ \ cout\ $<$$<$\ \texttt{"{}Contact\ gehaald\ :\ "{}}; \\
463\mbox{}\texttt{461:} \ \ \} \\
464\mbox{}\texttt{462:} \ \ \textbf{if}\ (\ slagen\ $<$\ hoogte\ )\ \{ \\
465\mbox{}\texttt{463:} \ \ \ \ \textbf{if}\ (printdetails) \\
466\mbox{}\texttt{464:} \ \ \ \ \ \ cout\ $<$$<$\ \texttt{"{}TEKORT"{}}; \\
467\mbox{}\texttt{465:} \ \ \}\ \textbf{else}\ \textbf{if}\ (\ slagen\ ==\ hoogte\ )\ \{ \\
468\mbox{}\texttt{466:} \ \ \ \ \textbf{if}\ (printdetails) \\
469\mbox{}\texttt{467:} \ \ \ \ \ \ cout\ $<$$<$\ \texttt{"{}CORRECT"{}}; \\
470\mbox{}\texttt{468:} \ \ \}\ \textbf{else}\ \{ \\
471\mbox{}\texttt{469:} \ \ \ \ \textbf{if}\ (printdetails) \\
472\mbox{}\texttt{470:} \ \ \ \ \ \ cout\ $<$$<$\ \texttt{"{}TEVEEL"{}}; \\
473\mbox{}\texttt{471:} \ \ \} \\
474\mbox{}\texttt{472:} \ \ \textbf{if}\ (printdetails) \\
475\mbox{}\texttt{473:} \ \ \ \ cout\ $<$$<$\ \texttt{"{}\ ("{}}\ $<$$<$\ slagen\ -\ hoogte\ $<$$<$\ \texttt{"{})"{}}\ $<$$<$\ endl; \\
476\mbox{}\texttt{474:} \\
477\mbox{}\texttt{475:} \ \ \textbf{return}\ (slagen\ -\ hoogte); \\
478\mbox{}\texttt{476:} \}\textit{//spel::uitslag} \\
479\mbox{}\texttt{477:} \\
480\mbox{}\texttt{478:} \textit{//===} \\
481\mbox{}\texttt{479:} \\
482\mbox{}\texttt{480:} void\ \textbf{printTotaalWaarde\ }(string\ type,\ double\ waarde,\ double\ totaal)\ \{ \\
483\mbox{}\texttt{481:} \ \ \ \ cout\ $<$$<$\ \textbf{setiosflags}(ios::left); \\
484\mbox{}\texttt{482:} \ \ \ \ cout\ $<$$<$\ \textbf{setw}(10)\ $<$$<$\ type\ $<$$<$\ \texttt{"{}\ :\ "{}}; \\
485\mbox{}\texttt{483:} \ \ \ \ cout\ $<$$<$\ \textbf{resetiosflags}(ios::left); \\
486\mbox{}\texttt{484:} \ \ \ \ double\ percent\ =\ (waarde\ /\ totaal)\ *\ 100; \\
487\mbox{}\texttt{485:} \ \ \ \ cout.\textbf{precision}(8); \\
488\mbox{}\texttt{486:} \ \ \ \ cout\ $<$$<$\ \textbf{setw}(8)\ $<$$<$\ waarde; \\
489\mbox{}\texttt{487:} \ \ \ \ cout\ $<$$<$\ \texttt{"{}\ =\ "{}}; \\
490\mbox{}\texttt{488:} \ \ \ \ cout.\textbf{precision}(2); \\
491\mbox{}\texttt{489:} \ \ \ \ cout\ $<$$<$\ \textbf{setw}(7)\ $<$$<$\ \textbf{setiosflags}(ios::fixed)\ $<$$<$\ percent \\
492\mbox{}\texttt{490:} \ \ \ \ $<$$<$\textbf{resetiosflags}(ios::fixed)\ $<$$<$\ \texttt{"{}\%"{}}; \\
493\mbox{}\texttt{491:} \ \ \ \ cout\ $<$$<$\ endl; \\
494\mbox{}\texttt{492:} \\
495\mbox{}\texttt{493:} \}; \\
496\mbox{}\texttt{494:} \\
497\mbox{}\texttt{495:} int\ \textbf{main\ }(\ )\ \{ \\
498\mbox{}\texttt{496:} \ \ int\ retcode\ =\ 0; \\
499\mbox{}\texttt{497:} \ \ int\ tekort\ =\ 0; \\
500\mbox{}\texttt{498:} \ \ int\ correct\ =\ 0; \\
501\mbox{}\texttt{499:} \ \ int\ teveel\ =\ 0; \\
502\mbox{}\texttt{500:} \ \ double\ eindscore\ =\ 0; \\
503\mbox{}\texttt{501:} \ \ int\ fout,\ goed; \\
504\mbox{}\texttt{502:} \\
505\mbox{}\texttt{503:} \ \ spel\ S; \\
506\mbox{}\texttt{504:} \ \ int\ randInit; \\
507\mbox{}\texttt{505:} \\
508\mbox{}\texttt{506:} \ \ \textit{/*\ Variabelen\ */} \\
509\mbox{}\texttt{507:} \ \ int\ logNiveau\ =\ SILENT;\ \textit{/*\ print\ niveau\ SILENT$|$VERBOSE\ */} \\
510\mbox{}\texttt{508:} \ \ double\ aantalKeer\ =\ 1000;\ \ \textit{/*\ aantal\ rondes\ */} \\
511\mbox{}\texttt{509:} \\
512\mbox{}\texttt{510:} \ \ \textit{/*\ initialiseer\ random-generator,\ maar\ print\ seed\ om\ debugging} \\
513\mbox{}\texttt{511:} \textit{\ \ \ *\ mogelijk\ te\ maken} \\
514\mbox{}\texttt{512:} \textit{\ \ \ */} \\
515\mbox{}\texttt{513:} \ \ randInit\ =\ \textbf{time}(0); \\
516\mbox{}\texttt{514:} \ \ cout\ $<$$<$\ \texttt{"{}RandInit\ getal:\ "{}}\ $<$$<$\ randInit\ $<$$<$\ endl; \\
517\mbox{}\texttt{515:} \ \ \textbf{srand\ }(randInit);\ \\
518\mbox{}\texttt{516:} \\
519\mbox{}\texttt{517:} \ \ \textit{/*\ Speel\ de\ potjes\ */} \\
520\mbox{}\texttt{518:} \ \ \textbf{for}\ (int\ i\ =\ 0;\ i\ $<$\ aantalKeer;\ i++)\ \{ \\
521\mbox{}\texttt{519:} \ \ \ \ S.\textbf{schud\ }(\ ); \\
522\mbox{}\texttt{520:} \ \ \ \ \textbf{if}\ (logNiveau) \\
523\mbox{}\texttt{521:} \ \ \ \ \ \ S.\textbf{print\ }(\ ); \\
524\mbox{}\texttt{522:} \\
525\mbox{}\texttt{523:} \ \ \ \ \textit{/*\ Niveau\ contract\ en\ spelers\ */} \\
526\mbox{}\texttt{524:} \ \ \ \ S.\textbf{maakcontract\ }(CONTRACT$\_$RANDOM,\ logNiveau); \\
527\mbox{}\texttt{525:} \ \ \ \ S.spelerniveau[0]\ =\ NIVEAU$\_$SLIM; \\
528\mbox{}\texttt{526:} \ \ \ \ S.spelerniveau[1]\ =\ NIVEAU$\_$RANDOM; \\
529\mbox{}\texttt{527:} \ \ \ \ S.spelerniveau[2]\ =\ NIVEAU$\_$RANDOM; \\
530\mbox{}\texttt{528:} \ \ \ \ S.spelerniveau[3]\ =\ NIVEAU$\_$RANDOM; \\
531\mbox{}\texttt{529:} \ \ \ \ \textbf{if}\ (logNiveau) \\
532\mbox{}\texttt{530:} \ \ \ \ \ \ \ \ \textbf{for}\ (int\ i\ =\ 0;\ i\ $<$=\ 3;\ i++) \\
533\mbox{}\texttt{531:} \ \ \ \ \ \ \ \ \ \ \ \ cout\ $<$$<$\ \texttt{"{}Niveau\ speler\ "{}}\ $<$$<$\ i\ $<$$<$\ \texttt{"{}:"{}}\ $<$$<$\ S.spelerniveau[i]\ $<$$<$\ endl; \\
534\mbox{}\texttt{532:} \\
535\mbox{}\texttt{533:} \ \ \ \ \textit{/*\ Afspelen\ bepaal\ type\ spel\ */} \\
536\mbox{}\texttt{534:} \ \ \ \ S.\textbf{afspelen\ }(SPEEL$\_$KOSTER$\_$BRIDGE,\ logNiveau); \\
537\mbox{}\texttt{535:} \\
538\mbox{}\texttt{536:} \ \ \ \ \textbf{if}\ (logNiveau) \\
539\mbox{}\texttt{537:} \ \ \ \ \ \ cout\ $<$$<$\ endl; \\
540\mbox{}\texttt{538:} \ \ \ \ retcode\ =\ S.\textbf{uitslag\ }(logNiveau); \\
541\mbox{}\texttt{539:} \\
542\mbox{}\texttt{540:} \ \ \ \ \textit{/*\ Boekhouding,\ voor\ de\ eindscore\ berekening\ */} \\
543\mbox{}\texttt{541:} \ \ \ \ \textbf{if}\ (retcode\ $>$\ 0)\ \{ \\
544\mbox{}\texttt{542:} \ \ \ \ \ \ \ \ teveel++; \\
545\mbox{}\texttt{543:} \ \ \ \ \ \ \ \ \textit{/*\ elk\ punt\ teveel\ score:\ -10\ */} \\
546\mbox{}\texttt{544:} \ \ \ \ \ \ \ \ eindscore\ =\ eindscore\ +\ retcode\ *\ -10; \\
547\mbox{}\texttt{545:} \ \ \ \ \}\ \textbf{else}\ \textbf{if}\ (retcode\ ==\ 0)\ \{ \\
548\mbox{}\texttt{546:} \ \ \ \ \ \ \ \ correct++; \\
549\mbox{}\texttt{547:} \ \ \ \ \ \ \ \ \textit{/*\ elk\ goede\ score\ +20\ */} \\
550\mbox{}\texttt{548:} \ \ \ \ \ \ \ \ eindscore\ =\ eindscore\ +\ 20; \\
551\mbox{}\texttt{549:} \ \ \ \ \}\ \textbf{else}\ \{ \\
552\mbox{}\texttt{550:} \ \ \ \ \ \ \ \ tekort++; \\
553\mbox{}\texttt{551:} \ \ \ \ \ \ \ \ \textit{/*\ elk\ punt\ tekort\ score:\ -20\ } \\
554\mbox{}\texttt{552:} \textit{\ \ \ \ \ \ \ \ \ *\ retcode\ is\ al\ negatief} \\
555\mbox{}\texttt{553:} \textit{\ \ \ \ \ \ \ \ \ */} \\
556\mbox{}\texttt{554:} \ \ \ \ \ \ \ \ eindscore\ =\ eindscore\ +\ (retcode\ *\ 20); \\
557\mbox{}\texttt{555:} \ \ \ \ \} \\
558\mbox{}\texttt{556:} \ \ \} \\
559\mbox{}\texttt{557:} \\
560\mbox{}\texttt{558:} \ \ \textit{/*\ Bereken\ eindresultaat\ */} \\
561\mbox{}\texttt{559:} \ \ fout\ =\ tekort\ +\ teveel; \\
562\mbox{}\texttt{560:} \ \ goed\ =\ correct; \\
563\mbox{}\texttt{561:} \ \ \textbf{printTotaalWaarde}(\texttt{"{}Tekort"{}},\ tekort,\ \ aantalKeer); \\
564\mbox{}\texttt{562:} \ \ \textbf{printTotaalWaarde}(\texttt{"{}Correct"{}},\ correct,\ \ aantalKeer); \\
565\mbox{}\texttt{563:} \ \ \textbf{printTotaalWaarde}(\texttt{"{}Teveel"{}},\ teveel,\ \ aantalKeer); \\
566\mbox{}\texttt{564:} \ \ cout\ $<$$<$\ endl; \\
567\mbox{}\texttt{565:} \ \ \textbf{printTotaalWaarde}(\texttt{"{}Goed"{}},\ goed,\ \ aantalKeer); \\
568\mbox{}\texttt{566:} \ \ \textbf{printTotaalWaarde\ }(\texttt{"{}Fout"{}},\ fout,\ aantalKeer); \\
569\mbox{}\texttt{567:} \ \ \textbf{printTotaalWaarde\ }(\texttt{"{}EindScore"{}},\ eindscore,\ aantalKeer\ *\ 20); \\
570\mbox{}\texttt{568:} \}\textit{//main} \\
571\mbox{}\texttt{569:} \\
572
Note: See TracBrowser for help on using the repository browser.