Programming for Nepali Traditional Game “Bagh Chaal”

I wrote simple console program for playing Nepal traditional board game “Bach Chal”.
But I have only 1 hour to make this program.
Then I could implemented only opening phase.
I’ll show you the way to play this program.
First, program shows start position of game.

Goat side Player can put goat 20 times.
Input two numbers of x-axis and y-axis of destinating position.

And return Enter.
You can see goat was putted.

When succeeded to put goat,Tiger side players turn starts.
Input tiger position which you want to move.
Then input move directory like that.

Goat eaten by tiger.
This is every thing of this program.
I’ll show the program all source code.
This program was compiled by gcc(it is free software distributed by FSF)
And executed by MSYS(it is also free software)

#include 

enum { FALSE, TRUE };
enum { EMPTY, TIGER, GOAT };

int position_ok(x,y){return 0<=x && x<5 && 0<=y && y<5;}

void print_board(int board[5][5]){
  int x,y;
  for(y=0;y<5;y++){
    if(y==0) printf("  0 1 2 3 4\n");
    printf("%d ",y);
    for(x=0;x<5;x++){
      switch(board[y][x]){
      case EMPTY:
        printf("_");
        break;
      case TIGER:
        printf("T");
        break;
      case GOAT:
        printf("G");
        break;
      default:
        fprintf(stderr, "Position is not valid!");
        break;
      }
      printf(" ");
    }
    printf("\n");
  }
  fflush(stdin);
}

void put_goat(int board[5][5]){
  printf("please position to put goat\n");
  fflush(stdin);
  int x, y;
  while(TRUE){
    scanf("%d %d",&y,&x);
    if(position_ok(x,y)){
      if(board[y][x]==EMPTY) break;
      else printf("that position already exists animal!\n");
    }else printf("position is invalid!\n");
    printf("please position to put goat\n");
    fflush(stdin);
  }
  board[y][x]=GOAT;
  print_board(board);
}
void move_tiger(int board[5][5]){
  printf("please select the tiger position\n");
  int x, y;
  while(TRUE){
    scanf("%d %d",&y,&x);
    if(position_ok(x,y)){
      if(board[y][x]==TIGER) break;
      else printf("doesn't exists tiger that position!\n");
    }else printf("position is invalid!\n");
    printf("please select the tiger position");
    fflush(stdin);
  }
  printf("please select the move direction of tiger\n");
  int dx,dy,next_x,next_y,eat_goat=FALSE;
  while(TRUE){
    scanf("%d %d",&dy,&dx);
    if(dx!=0 && dy!=0 && ((x-y)%2)!=0){
      printf("you can't move that direction!\n");
    }else{
      next_x=x+dx;
      next_y=y+dy;
      if(position_ok(next_x,next_y)){
        if(board[next_y][next_x]==EMPTY) break;
        else if(board[next_y][next_x]==GOAT) {
          next_x=next_x+dx;
          next_y=next_y+dy;
          if(position_ok(next_x,next_y)){
            if(board[next_y][next_x]==EMPTY){
              eat_goat=TRUE;
              break;
            }
          }
        }
      }
      printf("you can't move tiger there!\n");
    }
    printf("please select the move direction of tiger\n");
    fflush(stdin);
  }
  board[y][x]=EMPTY;
  board[next_y][next_x]=TIGER;
  if(eat_goat)board[y+dy][x+dx]=EMPTY;
  print_board(board);
}

int main()
{
  int remaining_goat=20;
  int board[5][5];
  int x, y;
  for(y=0;y<5;y++){
    for(x=0;x<5;x++){
      board[y][x]=EMPTY;
      if( ((x==0)||(x==4))&&((y==0)||(y==4)) ){
        board[y][x]=TIGER;
      }
    }
  }

  print_board(board);

  while(remaining_goat!=0){
    put_goat(board);
    remaining_goat--;
    printf("remaining goat is: %d\n",remaining_goat);
    move_tiger(board);
  }
  return 0;
}

Thank you for reading my first post.
Feel free to ask any question or request for this post!
Have a nice Monday!!

Advertisements

About ながとタン
嫁で彼女で妹の有希と二人でいろいろがんばってます!

2 Responses to Programming for Nepali Traditional Game “Bagh Chaal”

  1. Shaswat Sharma says:

    Good work, keep it up man. By the way, this is really a good stuff to learn c programming.

  2. I don’t know nepali game … but your effort can be seen … greate work

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: