Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: a little programming help ...

Author: Anthony Cozzie

Date: 18:52:20 04/24/04

Go up one level in this thread


On April 24, 2004 at 21:28:57, Mike Byrne wrote:

>This is the Windows source for "C" for move annoucnement.  It's a separate
>program that Crafty/windows calls for move annoucnement.  I would like to embed
>this program into Crafty so a user would not need two separate programs.
>
>Any ideas the best way to do this - I have tried - but not knowing enough about
>programming, all my attempls have failed.
>
>////////////////////////////////////////////////////////////////////////////////////////////
>// Speak.c
>//
>// Crafty 19.9 introduced "speaking" of moves by calling
>// external program speak with the move as its only argument.
>//
>// This program parses the move and plays it using English .wav files
>// obtained from http://www.playwitharena.com
>//
>//
>// Developed and compiled under MSVC 6 (SP5)
>//
>// History
>// -------
>// Jan. 10, 2004 - ver 1.00
>// Jan. 13, 2004 - ver 1.01 fix strcat of from / to strings
>//                          was strcat(cWork + 1, ...)
>////////////////////////////////////////////////////////////////////////////////////////////
>
>/******************************************************************************************/
>#include <string.h>
>#include <windows.h>
>#include <mmsystem.h>
>
>/******************************************************************************************/
>
>void SpeakMove(char *strFilename)
>{
>	char cWork[255];
>
>
>	strcpy(cWork, ".\\Sounds\\Eng\\");
>	strcat(cWork, strFilename);
>	strcat(cWork, ".wav");
>	PlaySound(cWork, NULL, SND_SYNC);
>}
>
>/******************************************************************************************/
>
>int main(int argc, char* argv[])
>{
>	if (argc == 2)
>		{
>		int x;
>		char cMove[255], cWork[255];
>
>
>		strcpy(cMove, argv[1]);
>
>		if (
>			(!strcmp(cMove, "O-O")) ||
>			(!strcmp(cMove, "O-O-O")) ||
>			(!strcmp(cMove, "Stalemate")) ||
>			(!strcmp(cMove, "Drawaccept")) ||
>			(!strcmp(cMove, "Drawoffer")) ||
>			(!strcmp(cMove, "Resign")) ||
>			(!strcmp(cMove, "Checkmate"))
>		   ) SpeakMove(cMove);
>		else
>			{
>			for (x = 0; x < (int)strlen(cMove); x++)
>				{
>				switch(cMove[x])
>					{
>					case 'R' :
>						SpeakMove("Rook");
>						break;
>
>					case 'N' :
>						SpeakMove("Knight");
>						break;
>
>					case 'B' :
>						SpeakMove("Bishop");
>						break;
>
>					case 'Q' :
>						SpeakMove("Queen");
>						break;
>
>					case 'K' :
>						SpeakMove("King");
>						break;
>
>					case 'P' :
>						SpeakMove("Pawn");
>						break;
>
>					case 'x':
>						SpeakMove("Takes");
>						break;
>
>					case '#':
>						SpeakMove("Checkmate");
>						break;
>
>					case 'a' :
>					case 'b' :
>					case 'c' :
>					case 'd' :
>					case 'e' :
>					case 'f' :
>					case 'g' :
>					case 'h' :
>						cWork[0] = cMove[x];
>						cWork[1] = '\0';
>						strcat(cWork, "from");
>						SpeakMove(cWork);
>						break;
>
>					case '1' :
>					case '2' :
>					case '3' :
>					case '4' :
>					case '5' :
>					case '6' :
>					case '7' :
>					case '8' :
>						cWork[0] = cMove[x];
>						cWork[1] = '\0';
>						strcat(cWork, "to");
>						SpeakMove(cWork);
>						break;
>
>					} // switch
>				} // for
>			} // else
>		} // if argc
>
>	return 0;
>}

Rather than system("speak"), spawn a new thread and pass in the move by hand.  A
little bit of overhead there, though.

What did you try, and why did it fail?

anthony



This page took 0 seconds to execute

Last modified: Thu, 15 Apr 21 08:11:13 -0700

Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.