You can win either way. - Saab General Bulletin Board - Saabnet.com
The banner above is an advertisment - if it asks you to download software, please ignore.
Site News - 7/1: Members: Log In to See Fewer Ads! | 5/28: SAAB Evolutions/TSN T-Shirts $14

[General | Members | C900 | 9000 | NG900 & OG93 | 93 | 95 | NG95 | 99 | Sonett | Vintage Models | Clubs | Other Cars | FAQs | Gifts | Member Photo Galleries | Member Directory | Classifieds | Manuals | *Buddy Registry | *Mileage Registry | Polls | What's New | Raffle | Photo of the Month | Sponsors]

General Bulletin Board
[Subscribe to Daily Digest]
(Search Author's Posts: e.g. Keyword:username)*Members Only


[Main General Bulletin Board | BBFAQ | Next by Date | Post Followup ] Member Login / Signup - Members see fewer ads. - Latest Member Gallery Photos
You can win either way.
Like This Post: - Subscribe to Daily Digest for this Bulletin Board
Posted by J (more from J) on Wed, 30 Apr 2003 07:19:31 Share Post by Email
In Reply to: Math and computer games, Nathan Pflaum [Profile/Gallery] , Sun, 27 Apr 2003 23:44:39
Alert me when someone posts in this thread:
Members do not see ads below this line. - Help Keep This Site Online - Signup

Hi,

The reason why it is tricky is because there are about 18^14 possible
permutations of moves.

Anyway, I wrote a program to figure out the game, and after crunching
numbers all night, it came up with a winning move for the case where
_you_ go first.

On your first move, leave 2 pearls on the last row (the one with 6
pearls).

Then, just modify the board in the following code:

---------------------------------------------------------------------

#include <stdafx.h>
#include <iostream.h>
#include <assert.h>

#error Don't compile this

#define EXAMINE_LEVEL 3

void solve_board
(
int *begin_board,
int *sure_win,
int *sure_loss,
int *winning_move_i,
int *winning_move_j,
int level
)
{
int *copy_board;
int i;
int j;
int sum;
int num_possible_moves;
int num_sure_losses;
int opp_sure_win;
int opp_sure_loss;
int opp_winning_move_i;
int opp_winning_move_j;

num_sure_losses = 0;
num_possible_moves = 0;
sum = 0;

*sure_win = FALSE;

*sure_loss = FALSE;

for(i=0;i<4;i++)
{
assert(begin_board[i]>=0);
sum+=(begin_board[i]);
}

if (0==sum)
{
*sure_win = TRUE;
}
else if (1==sum)
{
*sure_loss = TRUE;
}
else
{

copy_board = (int *)malloc(sizeof(int)*4);

for(i=0;i<4;i++)
{

if (level<EXAMINE_LEVEL)
{

cerr << "i : " << i << " level : " << level << endl;

}

if (begin_board[i])
{

memcpy(copy_board,begin_board,sizeof(int)*4);

for(j=(begin_board[i]-1);j>=0;j--)
{

if (level<EXAMINE_LEVEL)
{

cerr << "j : " << j << " level : " << level << endl;

}

num_possible_moves++;

copy_board[i] = j;

solve_board(copy_board,
&opp_sure_win,
&opp_sure_loss,
&opp_winning_move_i,
&opp_winning_move_j,
level+1
);

if (opp_sure_loss)
{
*sure_win = TRUE;
*winning_move_i = i;
*winning_move_j = j;
}
else if (opp_sure_win)
{
num_sure_losses++;
}

}
}
}

free(copy_board);

if (num_sure_losses==num_possible_moves)
{
*sure_loss = TRUE;
}
}

if ((level<EXAMINE_LEVEL) && (*sure_win))
{
cerr << "Intermediate Sure Win at level : " << level << endl;
}

} /* solve_board */

void foo(void)
{
int begin_board[4];
int sure_win;
int sure_loss;
int winning_move_i;
int winning_move_j;

begin_board[0] = 0;
begin_board[1] = 3;
begin_board[2] = 2;
begin_board[3] = 0;

solve_board(begin_board,
&sure_win,
&sure_loss,
&winning_move_i,
&winning_move_j,
0
);

if (sure_win)
{

cerr << endl << "Sure Win" << endl;
cerr << "Winning Move i : " << winning_move_i << endl;
cerr << "Winning Move j : " << winning_move_j << endl;

}
else
{
cerr << "No sure win" << endl;
}

} /* foo */

-----------------------------------------------------------------------

It will give you moves step by step. The computer has no chance.

thanks

Jae

posted by 172.140.4...


Posts in this Thread:
Alert me when someone posts in this thread:
Members do not see ads below this line. - Help Keep This Site Online - Signup
Post a Followup

No Site Registration is Required to Post - Site Membership is optional (Member Features List), but helps to keep the site online
for all Saabers. If the site helps you, please consider helping the site by becoming a member.

Name: Member Login / Signup - Members see fewer ads. - Latest Member Gallery Photos
E-Mail: (Optional)
Re-Enter E-Mail: (Confidential & Secure - Not revealed to other users!)
Note: Please check your spam folder for BB responses.

Subject:

Posting rules are simple - No for sale/wanted ads may be posted here - use the site classifieds.
You may not cross-post your message to multiple BBs.
Not permitted: political/religious topics and being disrespectful (personal attacks, insults, etc...).
Site Members do not see any red text, inline ad links, bottom of page anchor ads, box ads, or anti-spam check.

Message: (please no for sale/wanted classifieds - post those in the Saabnet.com Classifieds)
Links are now automatically made active, no need for any special code (or use the Option Link field below) - don't put links in () or end with a '.'
To add inline images to your post, use [img]http://www.domain.com/img.jpg[endimg] (or use the Optional Image Link field below).


Links are now automatically made active, no need for any special code (or use the Option Link field below) - don't put links in () or end with a '.'
To add inline images to your post above, use [img]http://www.domain.com/img.jpg[endimg] (or use the Optional Image Link field below).

Optional Link: (e.g. http://www.saabnet.com/)
Link Title: (Optional)
Optional Photo/Image Link: (e.g. http://www.saabnet.com/img.jpg)
Photo/Image to Upload: (Please be patient while file uploads)





StateOfNine.com
SaabClub.com
Jak Stoll Performance
M Car Covers
Ad Available

The content on this site may not be republished without permission. Copyright © 1988-2024 - The Saab Network - saabnet.com.
For usage guidelines, see the Mission & Privacy Notice.
[Contact | Site Map | Saabnet.com on Facebook | Saabnet.com on Twitter | Shop Amazon via TSN | Site Donations]

Random Saabnet.com Member Gallery Photos (Click Image)

This is a moderated bulletin board - Posting is a privilege, not a right. Unsolicited commercial postings are not allowed (no spam). Please, no For Sale or Wanted postings, SERIOUSLY. Classifieds are to be listed in The Saab Network Classifieds pages. This is a problem solving forum for over 250,000 Saab owners, so expect to see problems discussed here even though our cars are generally very reliable. This is not an anything goes type of forum. Saabnet.com has been a moderated forum since 1988. For usage guidelines, see the Saabnet.com Mission and Purpose Page. Please remember that you are not anonymous. Site Contact | Site Donations | Other Sites by SP - Poverty2Prosperity.org | Run Club Menlo Park | ScreenBot



Site Members do not see red text instructions, bottom of the page anchor ads, or box ads.
Click here to see all the Site Membership Benefits!