[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: [pbmserv-dev] Entirely new question from the new guy



Thanks, that was great.  Now I have a new snag.  I've simplified my
win-scenario code for testing purposes.  When one player hits the win
condition, the win isn't reported until the next player makes their move.
It correctly reports who the winner was, but that next move should not be
allowed to take place.  

Separately (and less importantly) I was getting stack dumps after a win
because I was tripping over something in the ratings code.  I disabled
ratings as a band-aid - is there a better fix?

Mike

-----Original Message-----
From: owner-pbmserv-dev@gamerz.net [mailto:owner-pbmserv-dev@gamerz.net] On
Behalf Of John Williams
Sent: Wednesday, June 29, 2005 5:09 PM
To: pbmserv-dev@gamerz.net
Subject: Re: [pbmserv-dev] Entirely new question from the new guy

MakeMove should return a move string, such as

  return "1";

"return 0;" is considered an indication that an error occured, but you did
not call Error to send the error message.

~ John Williams


On Wed, 29 Jun 2005, Michael Hammond wrote:

> Hey gang,
>
>    Now that my server runs, I'm trying out coding a simple game just to
see
> if I can.  The code compiles, I can successfully initiate a challenge and
> see the startup boards, but when the first player sends the first move,
the
> program returns no output.  If the second player tries to send a move, he
> gets a message saying that it's not his turn, and shows the board.  Like
so:
>
> ---------------------------
> Instructor@Instructor /cygdrive/c/temp
> $ ./tictactoe move 9 test1 test1 1
>
> Instructor@Instructor /cygdrive/c/temp
> $ ./tictactoe move 9 test2 test2 1
> From: Richard's PBeM Server <pbmserv@gamerz.net>
> Message-Id: <pbmserv.1120082477.3784.9@play.gamerz.net>
> To: test1@abacustech.info
> Subject: TicTacToe Board 9 Error
>
> It is not your move
>
> Summary of TicTacToe Board 9
>
> Please start the game test1.
>
>    Ohs (o)      Eks (x)
>    test1        test2
>
>
>  . | . | .
> -------------
>  . | . | .
> -------------
>  . | . | .
>


To unsubscribe, send a message to esquire@gamerz.net with
	unsubscribe pbmserv-dev@gamerz.net
as the BODY of the message.  The SUBJECT is ignored.
#include <sys/types.h>
#include <ctype.h>
#include <time.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

#include "tictactoe.h"
 
const char *Tictactoe::Cols = "abc";

void Tictactoe::PrintBoard(FILE *fp)
{
	
	fprintf(fp, " %c | %c | %c\n",GetAt(0,0),GetAt(0,1),GetAt(0,2));
	fprintf(fp, "-------------\n");
	fprintf(fp, " %c | %c | %c\n",GetAt(1,0),GetAt(1,1),GetAt(1,2));
	fprintf(fp, "-------------\n");
	fprintf(fp, " %c | %c | %c\n",GetAt(2,0),GetAt(2,1),GetAt(2,2));
}

const char *Tictactoe::MakeMove(const char *move)
{

	/* Move is an integer 1-9
	
	 1 | 2 | 3
	 ---------
	 4 | 5 | 6
	 ---------
	 7 | 8 | 9
	
	*/

	int row, col;
	//const char *newmove = DecodeMove(move,col,row);

	//if (newmove == NULL) return NULL;
     row = (int)floor((atoi(move)-1)/3);
	 col = ((atoi(move))-1) % 3;
	
	if (col < 0 || col > 2 || row < 0 || row > 2) {
		return (char*)Error("Please enter a number between 1 and 9");
	}

	if (!IsBlank(row,col))
		return (char*)Error("Position %s is occupied.  Try another position", move);

	PutAt(row,col, PlayerPieces(CurrentPlayer()));

	last.Init();
	last.Add(row).Add(col);

	return move;
}


int Tictactoe::IsGameOver(const char *&winner)
{
	int row, col;
	/* Check for win... */

	/*if  ((GetAt(0,0)==GetAt(0,1)==GetAt(0,2)==PlayerPieces(CurrentPlayer())) ||
	     (GetAt(1,0)==GetAt(1,1)==GetAt(1,2)==PlayerPieces(CurrentPlayer())) ||
	     (GetAt(2,0)==GetAt(2,1)==GetAt(2,2)==PlayerPieces(CurrentPlayer())) ||
	     (GetAt(0,0)==GetAt(1,0)==GetAt(2,0)==PlayerPieces(CurrentPlayer())) ||
	     (GetAt(0,1)==GetAt(1,1)==GetAt(2,1)==PlayerPieces(CurrentPlayer())) ||
	     (GetAt(0,2)==GetAt(1,2)==GetAt(2,2)==PlayerPieces(CurrentPlayer())) ||
	     (GetAt(0,0)==GetAt(1,1)==GetAt(2,2)==PlayerPieces(CurrentPlayer())) ||
	     (GetAt(0,2)==GetAt(1,1)==GetAt(2,0)==PlayerPieces(CurrentPlayer())) ) { 
	*/	 
	if ( GetAt(1,1)==PlayerPieces(CurrentPlayer())) {
		 winner = players[CurrentPlayer()];
		 return 1;
	}

	for (col=0 ; col<= 2 ; col++)
		for (row=0 ; row <=2 ; row++)
		if (IsBlank(row,col))
			return 0;

	winner = NULL;
	return 1;
}


int Tictactoe::Init(void)
{
	if (parameters.Count() > 0)
		return Error("%s does not take parameters", GameType());
	last.Init();
	last.Add(Unused).Add(Unused);
	return Board2D::Init(3,3);
}