[2] | 1 | #include <iostream>
|
---|
| 2 |
|
---|
| 3 | using namespace std;
|
---|
| 4 | int stapel[3];
|
---|
| 5 |
|
---|
| 6 |
|
---|
| 7 | //Controleer of er precies 1 stapel is met een waarde lager dan 2
|
---|
| 8 | //Begin standaard met true en controleer op foute waardes
|
---|
| 9 | bool afgelopen() {
|
---|
| 10 | bool einde = true;
|
---|
| 11 | int stapelsMetWaarde = 0;
|
---|
| 12 | int totaalWaarde = 0;
|
---|
| 13 | for( int ctr=0; ctr < 3; ctr++ ) {
|
---|
| 14 | if( stapel[ctr] > 0 ) {
|
---|
| 15 | totaalWaarde = totaalWaarde + stapel[ctr];
|
---|
| 16 | stapelsMetWaarde++;
|
---|
| 17 | if( (totaalWaarde > 2) or (stapelsMetWaarde > 1) ) {
|
---|
| 18 | einde = false;
|
---|
| 19 | break;
|
---|
| 20 | } //end if
|
---|
| 21 | } //end if not 0
|
---|
| 22 | } //end loop
|
---|
| 23 | return(einde);
|
---|
| 24 | }
|
---|
| 25 |
|
---|
| 26 |
|
---|
| 27 | //Controleer of een pad zeker winnend is
|
---|
| 28 | bool winstRecur( bool aanBeurt ) {
|
---|
| 29 | bool winst1 = false;
|
---|
| 30 | bool winst2 = false;
|
---|
| 31 | aanBeurt = not(aanBeurt);
|
---|
| 32 | if( afgelopen() ) {
|
---|
| 33 | if( aanBeurt ) {
|
---|
| 34 | return(true);
|
---|
| 35 | }
|
---|
| 36 | else {
|
---|
| 37 | return(false);
|
---|
| 38 | }
|
---|
| 39 | }
|
---|
| 40 | else {
|
---|
| 41 | for( int ctr=0; ctr < 3; ctr++ ) {
|
---|
| 42 | if( stapel[ctr] > 0 ) {
|
---|
| 43 | if( stapel[ctr] > 1 ) {
|
---|
| 44 | stapel[ctr] = stapel[ctr] - 2;
|
---|
| 45 | winst2 = winstRecur( aanBeurt );
|
---|
| 46 | stapel[ctr] = stapel[ctr] + 2;
|
---|
| 47 | } //end if (test met 2)
|
---|
| 48 | stapel[ctr] = stapel[ctr] - 1;
|
---|
| 49 | winst1 = winstRecur( aanBeurt );
|
---|
| 50 | stapel[ctr] = stapel[ctr] + 1;
|
---|
| 51 | } //end if (groter dan 0)
|
---|
| 52 | if( winst1 & winst2 ) {
|
---|
| 53 | return(true);
|
---|
| 54 | } //end if (winst test)
|
---|
| 55 | } //end for loop
|
---|
| 56 | return(false);
|
---|
| 57 | }
|
---|
| 58 | }
|
---|
| 59 |
|
---|
| 60 |
|
---|
| 61 | //Deze functie creert alle mogelijk vervolg zetten, en test deze op
|
---|
| 62 | //winnend
|
---|
| 63 | void winnend( int & stapelNummer, int & aantal ) {
|
---|
| 64 | bool winst;
|
---|
| 65 | for( int ctr=0; ctr < 3; ctr++ ) {
|
---|
| 66 | if( stapel[ctr] > 0 ) {
|
---|
| 67 | if( stapel[ctr] > 1) {
|
---|
| 68 | stapel[ctr] = stapel[ctr] - 2;
|
---|
| 69 | winst = winstRecur( "false" );
|
---|
| 70 | stapel[ctr] = stapel[ctr] + 2;
|
---|
| 71 | if( winst ) {
|
---|
| 72 | stapelNummer = ctr;
|
---|
| 73 | aantal = 2;
|
---|
| 74 | return;
|
---|
| 75 | } //winst 2
|
---|
| 76 | }
|
---|
| 77 | stapel[ctr] = stapel[ctr] - 1;
|
---|
| 78 | winst = winstRecur( "false" );
|
---|
| 79 | stapel[ctr] = stapel[ctr] + 1;
|
---|
| 80 | if( winst ) {
|
---|
| 81 | stapelNummer = ctr;
|
---|
| 82 | aantal = 1;
|
---|
| 83 | return;
|
---|
| 84 | } //winst 1
|
---|
| 85 | } //not null
|
---|
| 86 | } //loop for
|
---|
| 87 | stapelNummer = -1;
|
---|
| 88 | aantal = -1;
|
---|
| 89 | } //end winnnend
|
---|
| 90 |
|
---|
| 91 |
|
---|
| 92 | int main() {
|
---|
| 93 | stapel[0] = 4;
|
---|
| 94 | stapel[1] = 0;
|
---|
| 95 | stapel[2] = 0;
|
---|
| 96 | int a, t;
|
---|
| 97 | winnend(a,t);
|
---|
| 98 | cout << a << " " << t;
|
---|
| 99 | }
|
---|
| 100 |
|
---|