Example



WORD w;
char pFileName[512];
CFile f;
char buf[512];

strcpy( pFileName, "position.pos" );
f.Open( pFileName, CFile::modeRead );
CArchive ar( &f, CArchive::load, 512, buf );
// To write to file, use:
// f.Open( pFileName, CFile::modeCreate | CFile::modeWrite );
// CArchive ar( &f, CArchive::store, 512, buf );

ar >> w;
version = (int) w;
// First a check for which version that created the file
// Version = 124 means the versions 1.0, 1.1 or 1.2
// Version = 125 means the versions 1.6 to 2.5
// Version = 126 means 3.0 or newer
// When writing, use 126

if ( version < 124 || version > 126 )
{
	// Not a JellyFish Position file!
	return;
}

if ( version == 126 )
// 3.0
{
	ar >> w;	use caution = (BOOL) w;
	ar >> w;	// Not in use
}

if ( version == 125 || version == 126 )
// 1.6 or newer
{
	// 3 variables not used by older version
	ar >> w;	use cube = (BOOL) w;
	ar >> w;	jacoby = (BOOL) w;
	ar >> w;	beaver = (BOOL) w;
	if ( version == 125 )
	{
		// If reading, caution can be set here
		use caution =
	}
}

if ( version == 124 )
// 1.0, 1.1 or 1.2
{
	// If reading, the other variables can be set here
	use cube =
	jacoby =
	beaver =
	use caution =
}

ar >> w;	cube value = (int) w;
ar >> w;	cube owner = (int) w;
// Owner: 1 or 2 is player 1 or 2, 
// respectively, 0 means cube in the middle

ar >> w;	on roll = (int) w;
// 0 means starting position. 
// If you add 2 to the player (to get 3 or 4)
// it means that the player is on roll 
// but the dice have not been rolled yet.

ar >> w;	moves left = (int) w;
ar >> w;	moves right = (int) w;
// These two variables are used when you use movement #1,
// (two buttons) and tells how many moves you have left 
// to play with the left and the right die, respectively. 
// Initialized to 1 (if you roll a double, left = 4 and
// right = 0). If movement #2 (one button), only the first 
// one (left) is used to store both dice.

ar >> w;	not in use = w;

ar >> w;	game or match = (int) w;
// 1 = match, 3 = game

ar >> w;	opponent = (int) w;
// 1 = 2 players, 2 = JF plays one side

ar >> w;	level = (int) w;

ar >> w;	match length = (int) w;
// 0 if single game
ar >> w;	match score player 1 = (int) w;
ar >> w;	match score player 2 = (int) w;
// Can be whatever if match length = 0

ar >> name player 1;
ar >> name player 2;

ar >> w;	swap dice = (BOOL) w;
// TRUE if lower die is to be drawn to the left

ar >> w;	crawford = (int) w;
// 1 = pre-Crawford, 2 = Crawford, 3 = post-Crawford

ar >> w;	JF played last = (BOOL) w;
ar >> last move;
// Stores whether the last move was played by JF
// If so, the move is stored in a string to be 
// displayed in the 'Show last' dialog box

ar >> w;	die1 = abs( (int) w );
ar >> w;	die2 = (int) w;
if ( die1 <0 ) { die1="pow(" 2, 8*sizeof(WORD) ); } // In the end the position itself is stored, // as well as the old position to be able to undo. // The two position arrays can be read like this: int pNew[ 26 ]; int pOld[ 26 ]; for ( int i="0;" i < 26; i++ ) { ar>> w;
	pNew[ i ]=( (int) w ) - 20;
	ar >> w;
	pOld[ i ]=( (int) w ) - 20;
	// 20 has been added to each number when storing
}
// Player 1's checkers are represented with negative numbers, 
// player 2's with positive. The arrays are representing the 
// 26 different points on the board, starting with pNew[0]
// which is the upper bar and ending with pNew[25] which is 
// the bottom bar. The remaining numbers are in the opposite 
// direction of the numbers you see if you choose 'Numbers' 
// from the 'View' menu, so pNew[1] is marked number 24
// on the screen.

ar.Close();
f.Close();
// When finished, close the archive as well as the file

 Back to the JellyFish HomePage


Copyright © 1998-2002 JellyFish AS. All rights reserved.
Last updated Comments to
info@jelly.effect.no