Beispiel #1
0
void
test_move_row_west(void)
{
	board_t *board;

	char *bstr1[] = { "1", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0" };
	board = create_board(bstr1, NORTH, 4, 4, 4);
	mov_row_west(board, 0);
	assert_row0(board, P1, P0, P0, P0);
	free(board);

	char *bstr2[] = { "1", "1", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0" };
	board = create_board(bstr2, NORTH, 4, 4, 4);
	mov_row_west(board, 0);
	assert_row0(board, P1, P1, P0, P0);
	free(board);

	char *bstr3[] = { "1", "2", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0" };
	board = create_board(bstr3, NORTH, 4, 4, 4);
	mov_row_west(board, 0);
	assert_row0(board, P3, P0, P0, P0);
	free(board);

	char *bstr4[] = { "1", "2", "2", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0" };
	board = create_board(bstr4, NORTH, 4, 4, 4);
	mov_row_west(board, 0);
	assert_row0(board, P3, P2, P0, P0);
	free(board);

	char *bstr5[] = { "2", "2", "2", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0" };
	board = create_board(bstr5, NORTH, 4, 4, 4);
	mov_row_west(board, 0);
	assert_row0(board, P2, P2, P2, P0);
	free(board);
}
Beispiel #2
0
int main() {
  initscr();
  cbreak();
  noecho();
  keypad(stdscr, TRUE); // make keys work
  curs_set(0); // hide cursor
  timeout(100);

  int xmax;
  int ymax;
  getmaxyx(stdscr, ymax, xmax);
  enum Direction dir = RIGHT;

  Board* board = create_board(create_snake(), NULL, xmax, ymax);
  int i;
  for (i = 0; i < 6; i++) {
    add_new_food(board);
  }

  while(true) {
    erase();
    display_points(board->snake, ACS_BLOCK);
    display_points(board->foods, ACS_DIAMOND);
    dir = get_next_move(dir);
    enum Status status = move_snake(board, dir);
    if (status == FAILURE) break;
  }
  endwin();

  return 0;
}
Beispiel #3
0
/*
 * Completely redraw *everything*
 */
void
full_redraw(scrgame *sg)
{
  static char *name = NULL;
  static size_t vers_len;
  static const char *helpstr = "? : help";
  static const size_t helplen = 8;
  if (!name) {
    name = getgname(sg->game);
  }
  /* 10 = strlen(" version ") */
  vers_len = strlen(name) + strlen(VERSION) + 10;
  delwin(sg->board_w);
  delwin(sg->score_w);
  delwin(sg->msg_w);
  clear();
  /* We want the ends of the version string and of
   * helpstr to line up. */
  mvprintw(versrow, helpcol + helplen - vers_len,
	   "%s version %s", name, VERSION);
  mvprintw(helprow, helpcol, helpstr);
  refresh();
  sg->board_w = create_board(sg->game);
  sg->score_w = create_scorebox(sg->game);
  sg->msg_w = create_msgbox();
}
int main(int argc, char* argv[]) {
	
	board_t* board = create_board();
	symbol_t result;
	symbol_t current_symbol = X;

	move_t m;
 	m.i = 1;
	m.j = 1;
	//put_symbol(board, 0, &m);

//	print_board(board);

	while(1) {
		printf("Player %i to move next\n", (int) current_symbol);
		move(board, current_symbol, 0, -9999, 9999);
	//	print_board(board);
		result = winner(board);
	
		if(result != EMPTY) {
			break;
		}

		current_symbol = 1 - current_symbol;
	}

	printf("Winner: %i\n:", (int) result);

	return 0;
}
int play_game( individual* p1, individual* p2 ) {
	board* b;
	play* next_play;
	play_list* pl;
	int x, player, result;
	cgp_net* net;

	b = create_board();
	player = MAX;
	while( game_status( b ) == NOT_DONE ) {
		pl = create_possible_plays( b, player );

		/* choose play */
		if( player == MAX ) {
			net = p1->net;
		} else {
			net = p2->net;
		}
		/* this is combining too much into one function */
		next_play = select_play( pl, player, net );
		

		/* switch active player */
		if( player == MAX ) {
			player = MIN;
		} else {
			player = MAX;
		}
	}
	result = game_status( b );
	delete_board( b );
	/* record wins / loss / draw */
	return( result );
}
Beispiel #6
0
int main() {
  int *board = create_board();

  check_winner(board);

  return 0;
}
Beispiel #7
0
//program to implement the game of minesweeper
//user enters the name of the executable, the row and column dimensions, number of mines, and optionally a seed for random number generator 
int main(int argc, char** argv){
	
	Board board; //intitialize the board with struct type Board
	
  	int row = 0; //intialize the number of rows
  	int column = 0; //initialize the number of columns
  	int mine = 0; //intiialize the number of mines
  	read_args(argc, argv, &row, &column, &mine);
  	board.row = row;
  	board.col = column;
  	board.mine = mine;


	board.seed = generate_seed(argv);
	board.tile = create_board(board); //create the board
	mine_location_generator(board);
	print_board(board);
	play_is_valid(board);



	destroy_board(board); //when the game is over destroy the board

  return 0;
}
Beispiel #8
0
void
test_possible_pieces(void)
{
	board_t *board;
	uint64_t possible_pieces;
	char *bstr[] = {
		"0", "0", "0", "0",
		"0", "0", "0", "0",
		"0", "0", "0", "0",
		"0", "0", "0", "0"
	};

	board = create_board(bstr, 0, 0, 0, 0);
	possible_pieces = comp_possible_pieces(board);
	assert((possible_pieces & (1 << P0)) == 0);
	assert((possible_pieces & (1 << P1)) == 0);
	assert((possible_pieces & (1 << P2)) == 0);
	assert((possible_pieces & (1 << P3)) == 0);
	free(board);

	board = create_board(bstr, 0, 4, 4, 4);
	possible_pieces = comp_possible_pieces(board);
	assert((possible_pieces & (1 << P0)) == 0);
	assert((possible_pieces & (1 << P1)) > 0);
	assert((possible_pieces & (1 << P2)) > 0);
	assert((possible_pieces & (1 << P3)) > 0);
	assert(board->n_ones == 4);
	assert(board->n_twos == 4);
	assert(board->n_threes == 4);
	free(board);

	bstr[0] = "768";
	board = create_board(bstr, 0, 4, 4, 4);
	possible_pieces = comp_possible_pieces(board);
	assert((possible_pieces & (1 << P0)) == 0);
	assert((possible_pieces & (1 << P1)) > 0);
	assert((possible_pieces & (1 << P2)) > 0);
	assert((possible_pieces & (1 << P3)) > 0);
	assert((possible_pieces & (1 << P6)) > 0);
	assert((possible_pieces & (1 << P12)) > 0);
	assert((possible_pieces & (1 << P24)) > 0);
	assert((possible_pieces & (1 << P48)) > 0);
	assert((possible_pieces & (1 << P96)) > 0);
	assert((possible_pieces & (1 << P192)) == 0);
	free(board);
}
void create_possible_plays_evaluate( ) {
	board *b;
	play_list *pl;
	b = create_board();
	pl = create_possible_plays( b, 1 );
	print_play_list( pl );
	delete_possible_plays( pl );
}
Beispiel #10
0
void
test_player_make_move(void)
{
	board_t *board, *eboard;
	char *bstr[] = {
		"1", "0", "3", "3",
		"2", "1", "3", "6",
		"0", "2", "0", "6",
		"0", "0", "0", "0"
	};
	char *bstr_expected[] = {
		"3", "1", "6", "3",
		"0", "2", "0", "12",
		"0", "0", "0", "0",
		"0", "0", "0", "0"
	};
	int x, y;

	board = create_board(bstr, NORTH, 4, 4, 4);
	eboard = create_board(bstr_expected, NORTH, 4, 4, 4);
	player_make_move(board, NORTH);
	for (y = 0; y < 4; y++) {
		for (x = 0; x < 4; x++) {
			assert(PIECE(board->b, x, y) == PIECE(eboard->b, x, y));
		}
	}
	free(board);

	char *bstr2[] = {
		"1", "6", "192", "2",
		"1", "6", "48", "12",
		"1", "12", "96", "0",
		"3", "3", "2", "3"
	};
	char *bstr2_expected[] = {
		"1", "12", "192", "2",
		"1", "12", "48", "12",
		"1", "3", "96", "0",
		"3", "0", "2", "3"
	};
	board = create_board(bstr, NORTH, 4, 4, 4);
	eboard = create_board(bstr_expected, NORTH, 4, 4, 4);
	dir_t best_move = alpha_beta_next_move(board, 10);
	printf("%d\n", best_move);
	free(board);
}
play *create_play() {
	play *p;

	p = ( play* ) malloc ( sizeof( play ) );
	if( p == 0 ) { printf( "Malloc failed\n" ); exit( 1 ); }
	p->board = create_board();
	p->eval = NOT_EVALUATED;
	return p;
}
/**
 * Read a file of (i,j) pairs specifying an initial set of live cells
 */
void read_board(problem_t* problem)
{
    FILE* fp = fopen(problem->init, "r");
    int i, j;
    if (fp == NULL) {
        fprintf(stderr, "Could not open board file: %s\n", problem->init);
        exit(-2);
    }
    create_board(problem);
    while (fscanf(fp, "%d %d", &i, &j) == 2)
        set_cell(problem, i, j);
    fclose(fp);
}
Beispiel #13
0
void
test_comp_make_move(void)
{
	board_t *board;
	char *bstr[] = {
		"0", "0", "0", "0",
		"0", "0", "0", "0",
		"0", "0", "0", "0",
		"0", "0", "0", "0"
	};

	board = create_board(bstr, NORTH, 4, 4, 4);
	comp_make_move(board, C2I(0, 3), P1);
	assert(PIECE(board->b, 0, 3) == P1);
	assert(board->n_ones == 3);
	free(board);

	board = create_board(bstr, NORTH, 0, 0, 1);
	comp_make_move(board, C2I(0, 3), P3);
	assert(PIECE(board->b, 0, 3) == P3);
	assert(board->n_ones == 4);
	free(board);
}
Beispiel #14
0
//main function that starts the program
//program to execute the game of Connect-4, except the user can define the size of the board and how many pieces are needed to win
int main(int argc, char** argv){
	int num_rows = 0; //initialize variables that will be entered by the user
	int num_columns = 0;
	int plays_to_win = 0;
	int turn_count = 1;


	read_args(argc, argv, &num_rows, &num_columns, &plays_to_win); //pass the variables as pointers so that their values can be updated
	char** board = create_board(num_rows, num_columns);
	execute_game(board, num_rows, num_columns, plays_to_win, turn_count); 
	destroy_board(board, num_rows); //when the game is over, the board can be destroyed


	return 0;
}
void test_for_memory_leaks() {
	int x;
	board *board;
	play *play;
	play_list *pl;
	
	/*
	printf( "Hit enter to test board creation and deletion\n" );
	getchar();
	*/
	printf( "Testing board creation and deletion\n" );
	for( x = 0; x < 100000; x++ ) {
		board = create_board( );
		// printf( "%d\n", board );
		delete_board( board );
	}
		// printf( "%d\n", board );

	/*
	printf( "Hit enter to test play creation and deletion\n" );
	getchar();
	*/
	printf( "Testing play creation and deletion\n" );
	for( x = 0; x < 100000; x++ ) {
		play = create_play( );
		printf( "%d\n", play );
		delete_play( play );
	}
	printf( "%d\n", play );

	/*
	printf( "Hit enter to test play list creation and deletion\n" );
	getchar();
	*/

	printf( "Testing play list creation and deletion\n" );
	for( x = 0; x < 1000000; x++ ) { 
		pl = create_play_list( 5 );
		/* print_play_list( pl ); */
		printf( "%d\n", pl );
		delete_play_list( pl );
	}
	printf( "%d\n", pl );
}
Beispiel #16
0
void
test_possible_places(void)
{
	board_t *board;
	uint64_t possible_places;
	char *bstr[] = {
		"0", "0", "0", "0",
		"0", "0", "0", "0",
		"0", "0", "0", "0",
		"0", "0", "0", "0"
	};

	board = create_board(bstr, NORTH, 0, 0, 0);
	possible_places = comp_possible_places(board);
	assert(board->last_move_dir == NORTH);
	assert((possible_places & (1 << C2I(0,3))) > 0);
	assert((possible_places & (1 << C2I(1,3))) > 0);
	assert((possible_places & (1 << C2I(2,3))) > 0);
	assert((possible_places & (1 << C2I(3,3))) > 0);
	free(board);
}
int main(){
	board *b;
	play_list *pl;

	b = create_board();
	printf( "Blank Board\n" );
	print_board( b );
	b->state[0][0] = X;
	b->state[1][0] = X;
	b->state[2][0] = O;
	printf( "Populated Board\n" );
	print_board( b );

	pl = create_possible_plays( b, O );
	print_play_list( pl );

	printf( "Original Board\n" );
	print_board( b );

	delete_possible_plays( pl );
	delete_board( b );
	
}
void create_print_status_evaluate(){
	int a, b, c, d, e, f, g, h, i;
	board *board;
	board = create_board( );

	for( a = -1; a < 2; a++ ){
		for( b = -1; b < 2; b++ ){ 
			for( c = -1; c < 2; c++ ){
				for( d = -1; d < 2; d++ ){
					for( e = -1; e < 2; e++ ){
						for( f = -1; f < 2; f++ ){
							for( g = -1; g < 2; g++ ){
								for( h = -1; h < 2; h++ ){
									for( i = -1; i < 2; i++ ){
										board->state[0][0] = a;
										board->state[0][1] = b;
										board->state[0][2] = c;
										board->state[1][0] = d;
										board->state[1][1] = e;
										board->state[1][2] = f;
										board->state[2][0] = g;
										board->state[2][1] = h;
										board->state[2][2] = i;

										print_board( board );
										printf( "\n" );
									}
								}
							}
						}
					}
				}
			}
		}
	}
	delete_board( board );
}
Beispiel #19
0
string solve(string command,user*& cur_user)
{
  vector <string> commands;
  string x;

  string sol;
  commands=parse(command);
  x=commands[0];
  if(x=="exit" || x=="disconnect")
    return x;
  if(x=="signup")
    sol=signup(cur_user,commands);
  if(x=="signin")
    sol=signin(cur_user,commands);
  if(x=="signout" && commands.size()==1)
    {
      cur_user=NULL;
      return "signing out completed.\n";
    }
  if(x=="show_boards")
    sol=show_boards(cur_user);
  if(x=="enter_board")
    sol=enter_board(cur_user,commands);
  if(x=="add_user")
    sol=add_user(cur_user,commands);
  if(x=="remove_user_from_board")
    sol=remove_user_from_board(cur_user,commands);
  if(x=="show_lists" && commands.size()==1)
    sol=show_lists(cur_user);
  if(x=="show_cards")
    sol=show_cards(cur_user,commands);
  if(x=="show_card")
    sol=show_card(cur_user,commands);
  if(x=="create_board")
    sol=create_board(cur_user,commands);
  if(x=="remove_board")
    sol=remove_board(cur_user,commands);
  if(x=="add_list")
    sol=add_list(cur_user,commands);
  if(x=="remove_list")
    sol=remove_list(cur_user,commands);
  if(x=="add_card")
    sol=add_card(cur_user,commands);
  if(x=="remove_card")
    sol=remove_card(cur_user,commands);
  if(x=="move_card")
    sol=move_card(cur_user,commands);
  if(x=="rename_card")
    sol=rename_card(cur_user,commands);
  if(x=="edit_card_description")
    sol=edit_card_des(cur_user,commands);
  if(x=="edit_card_due_date")
    sol=edit_card_date(cur_user,commands);
  if(x=="assign_user")
    sol=assign(cur_user,commands);
  if(x=="remove_user")
    sol=remove_user_from_card(cur_user,commands);
  if(x=="comment")
    sol=commenting(cur_user,commands);
  if(x=="filter")
    sol=filter(cur_user,commands);
  if(sol.size()==0)
    sol="Invalid command.\n";
  return sol;
     
}
Beispiel #20
0
Game* 
create_game(GtkWidget* widget, GdkPixmap* pixmap) {
	Game* game = (Game*)malloc(sizeof(Game));
	game->board = create_board();
	game->red   = create_user(red);
	game->black = create_user(black);

	//create all chessman
	int index = 0;
	int i = 0;
	//create the red soldiers
	for(i=0; i<5; i++) {
		game->man[index] = create_chessman(red, soldier, index, game->board,
				game->red, red_soldier_image,3, i*2);
		index ++;
	}
	//create the red cannons
	for(i = 0; i < 2; i ++) {
		game->man[index] = create_chessman(red, cannon, index, game->board,
				game->red, red_cannon_image,2, 6*i + 1);
		index ++;
	}
	//create the red tanks
	for(i = 0; i < 2; i ++) {
		game->man[index] = create_chessman(red, tank, index, game->board,
				game->red, red_tank_image,0, 8*i);
		index ++;
	}
	//create the red horses
	for(i = 0; i < 2; i ++) {
		game->man[index] = create_chessman(red, horse, index, game->board,
				game->red, red_horse_image, 0, 6*i +1);
		index ++;
	}
	//create the red chancellors
	for(i = 0; i < 2; i ++) {
		game->man[index] = create_chessman(red, chancellor, index, game->board,
				game->red, red_chancellor_image, 0, 4*i +2);
		index ++;
	}
	//create the red scholars
	for(i = 0; i < 2; i ++) {
		game->man[index] = create_chessman(red, scholar, index, game->board,
				game->red, red_scholar_image, 0, 2*i +3);
		index ++;
	}
	game->man[index] = create_chessman(red, general, index, game->board,
			game->red, red_general_image, 0, 4);
	index ++;
	//create the black soldiers
	for(i=0; i<5; i++) {
		game->man[index] = create_chessman(black, soldier, index, game->board,
				game->black, black_soldier_image, 6, i*2);
		index ++;
	}
	//create the black cannons
	for(i = 0; i < 2; i ++) {
		game->man[index] = create_chessman(black, cannon, index, game->board,
				game->black, black_cannon_image, 7, 6*i + 1);
		index ++;
	}
	//create the black tanks
	for(i = 0; i < 2; i ++) {
		game->man[index] = create_chessman(black, tank, index, game->board,
				game->black, black_tank_image, 9, 8*i);
		index ++;
	}
	//create the black horses
	for(i = 0; i < 2; i ++) {
		game->man[index] = create_chessman(black, horse, index, game->board,
				game->black, black_horse_image, 9, 6*i +1);
		index ++;
	}
	//create the black chancellors
	for(i = 0; i < 2; i ++) {
		game->man[index] = create_chessman(black, chancellor, index, game->board,
				game->black, black_chancellor_image, 9, 4*i +2);
		index ++;
	}
	//create the black scholars
	for(i = 0; i < 2; i ++) {
		game->man[index] = create_chessman(black, scholar, index, game->board,
				game->black, black_scholar_image, 9, 2*i +3);
		index ++;
	}
	game->man[index] = create_chessman(black, general, index, game->board,
			game->black, black_general_image, 9, 4);
	index ++;
	game->current_user = game->red;
	game->current_man = NULL;
	game->level = 0;
	game->mode  = 0;

	draw_game(game, pixmap);
	gtk_widget_draw(widget, NULL);
	return game;
}
Beispiel #21
0
int bad_possible_elimination(sudoku_board board, int side){
	int i, j, k, n, m,aa=0, abc, alone_ok=0;
	sudoku_board test_board;
	//	print_board(board, side);
	
	for (i=0; i<side; ++i) {//ROW
		for (j=0; j<side; ++j) {//COLUMN
			//printf("row=%d  column=%d\n", i, j);
			//printf("\tvalue = %d\n", get_value(&board[i][j]));
			if (get_value(&board[i][j])==0) {
				for (k=0; k<side; ++k) {//POSSIBLE
					//printf("k=%d   possible=%d\n", k, board[i][j].possible[k]);
					if (board[i][j].possible[k]){
						test_board = create_board(side);
						for (n=0; n<side; ++n) 
							for (m=0; m<side; ++m){
								if (get_value(&board[n][m])) 
									found_value(test_board, side, n, m, get_value(&board[n][m]));
							}
						found_value(test_board, side, i, j, board[i][j].possible[k]);
						
						alone_ok=0;
						for (n=0; n<side; ++n) {
							if ((board[i][n].possibles)==1) {
								for (m=0; m<side; ++m) {
									if (board[i][n].possible[m]) {
										alone_ok = 1;
										found_value(test_board, side, i, n, board[i][n].possible[m]);
									}
								}
							}
							if ((board[n][j].possibles)==1) {
								for (m=0; m<side; ++m) {
									if (board[n][j].possible[m]) {
										alone_ok = 1;
										found_value(test_board, side, n, j, board[n][j].possible[m]);
									}
								}
							}
						}
						if (singleton(test_board, side, i, j, i+1, j+1))
							alone_ok = 1;
						if (pairs(test_board, side, i, j, i+1, j+1))
							alone_ok = 1;
						
						if (alone_ok) {
							while (1){
								if (alone(board, side))
									continue;

								if (singleton(board, side, 0, 0, side, side))
									continue;
								
								if (pairs(board, side, 0, 0, side, side))
									continue;
								break;
							}
						}
						
						
						
						abc = check_solution(test_board, side);
						//printf("%d\n", aa);
						switch (abc) {
							case 0:
								found_value(board, side, i, j, board[i][j].possible[k]);
								delete_board(test_board, side);
								return -1;
							case 1:
								delete_possible(&board[i][j], board[i][j].possible[k], side);
								++aa;
								break;
							default:
								break;
						}
						delete_board(test_board, side);
					}
				}
			}
		}
	}
	
	
	return aa;
}
Beispiel #22
0
// создание всех досок, кроме клановых и персональных
void Board::BoardInit()
{
	Board::BoardList.clear();

	create_board(GENERAL_BOARD, "Вече", "Базарная площадь", ETC_BOARD"general.board");
	create_board(NEWS_BOARD, "Новости", "Анонсы и новости Былин", ETC_BOARD"news.board");
	create_board(IDEA_BOARD, "Идеи", "Идеи и их обсуждение", ETC_BOARD"idea.board");
	create_board(ERROR_BOARD, "Ошибки", "Сообщения об ошибках в мире", ETC_BOARD"error.board");
	create_board(GODNEWS_BOARD, "GodNews", "Божественные новости", ETC_BOARD"god-news.board");
	create_board(GODGENERAL_BOARD, "Божества", "Божественная базарная площадь", ETC_BOARD"god-general.board");
	create_board(GODBUILD_BOARD, "Билдер", "Заметки билдеров", ETC_BOARD"god-build.board");
	create_board(GODCODE_BOARD, "Кодер", "Заметки кодеров", ETC_BOARD"god-code.board");
	create_board(GODPUNISH_BOARD, "Наказания", "Комментарии к наказаниям", ETC_BOARD"god-punish.board");
	create_board(NOTICE_BOARD, "Анонсы", "Сообщения от администрации", ETC_BOARD"notice.board");
	create_board(MISPRINT_BOARD, "Опечатки", "Опечатки в игровых локациях", ETC_BOARD"misprint.board");
}