[Search for users] [Overall Top Noters] [List of all Conferences] [Download this site]

Conference hydra::amiga_v1

Title:AMIGA NOTES
Notice:Join us in the *NEW* conference - HYDRA::AMIGA_V2
Moderator:HYDRA::MOORE
Created:Sat Apr 26 1986
Last Modified:Wed Feb 05 1992
Last Successful Update:Fri Jun 06 1997
Number of topics:5378
Total number of notes:38326

809.0. "C/AmigaDos/Windows question" by WHYVAX::KRUGER () Thu Oct 15 1987 03:17

    HELP! I can't figure out why this program is crashing! It must be
    because I'm trying to read and write to a window, but I don't know
    how to fix it. It is being compiled under Manx 3.4
    
    #include stdio.h

#define CLS "\014"
#define CSI "\0x9B"


#define STD_SIZE 19
#define BOARD_SIZE STD_SIZE*STD_SIZE

typedef enum {black,white,empty} ColorType;

typedef struct
{
  ColorType Color;
  int GroupSize,Liberties;
  int Members[BOARD_SIZE];
} GroupType;

typedef struct
{
  ColorType Color;
  GroupType *GroupPtr;
} BoardType;

BoardType Board[BOARD_SIZE];
ColorType CurrentColor;

FILE *fp;

gotoxy(y,x) int x,y;
{
  putc(0x9B,fp);
  fprintf(fp,"%d;%dH",y,x);
}

main()
{
  int Position;

  fp = fopen("CON:0/0/600/199/GO!","w+");
  InitBoard();
  CurrentColor = black;
  for (;;)
  {
    DisplayBoard();
    Position = EnterMove();
    Board[Position].Color = CurrentColor;
    ToggleColor();
  }
}

InitBoard()
{
  int i;
  for (i=0; i<361; i++)
    Board[i].Color = empty;
}

ToggleColor()
{
  if (CurrentColor == black)
    CurrentColor = white;
  else
    CurrentColor = black;
}

int EnterMove()
{
  char Row;
  int Col, Position;

  do
  {
    gotoxy(22,1);
    if (CurrentColor == white)
      fprintf(fp,"White's move:");
    else
      fprintf(fp,"Black's move:");
    fscanf(fp,"%c %d",&Row,&Col);
  }
  while(!(Row >= 'a' && Row <= 's') &&
	!(Row >= 'A' && Row <= 'S') ||
	!(Col >= 1 && Col <= 19));
  if (Row>= 'a' && Row <='s')
    Row-='a';
  else
    Row-='A';
  return Row*19 + Col - 1;
}

DisplayBoard()
{
  int i,j,Position;
  fputs(CLS "   ",fp);
  for (i=1; i<=19; i++)
    fprintf(fp,"%3d",i);
  fputc('\n',fp);
  Position = 0;
  for (i=0; i<19; i++)
  {
    fputc(i+65,fp);
    fputs(":  ",fp);
    for (j=0; j<19; j++)
      switch(Board[Position++].Color)
      {
	case black:
		fputs("  @",fp);
		break;
	case white:
		fputs("  O",fp);
		break;
	case empty:
		fputs("  .",fp);
		break;
      }
    fputc('\n',fp);
  }
}

T.RTitleUserPersonal
Name
DateLines