Ejemplo n.º 1
0
void select_move()
{
    if(G_current_game.cpu_mode == easy)
    {
        random_cpu(get_current_game_ptr()->board);
    }
    else
    {
        //if(G_current_game.cpu_mode == hard){
        smart(get_current_game_ptr()->board);
    }
}
/**
 * This function change the color of the last piece
 *
 * @v info_s	At the end of the game
 * @return	void
 * @date	2014-05-21
 * @author	PT Team
 **/
void refresh_last_piece(int i, int j)
{
                if (get_current_game_ptr()->board[i][j].lastPiece==0)
                {
                    get_current_game_ptr()->board[i][j].lastPiece = 2;
                }

                else
                {
                    if (get_current_game_ptr()->board[i][j].lastPiece==1)
                    {
                        get_current_game_ptr()->board[i][j].lastPiece = 3;
                    }
                }
}
Ejemplo n.º 3
0
int finish_game_wrapper(position_t current_pos){
    char S[1024];
    sprintf(S,"Calling finish_game: X=%d,Y=%d",current_pos.X, current_pos.Y_int);
    // debug_append_to_file("debug.txt", S);
    //return finish_game(get_current_game_ptr()->board,current_pos.X, current_pos.Y_int);
    return finish_gamePL(get_current_game_ptr()->board);
}
Ejemplo n.º 4
0
/**
 * Sets the content of the board in a specific row and column
 * The content is a define, which is the piece
 *
 * @v	board_size	PIECE is the define of '#'
 * @return		void
 * @date		2014-04-14
 * @author		Triplet VIOPE 2014 (PT TEAM)
 */
void board_set_content_row_col(int row, char col){

	position_t pos;
	pos.X = board_row_to_matrix_idx(row);
	pos.Y_int = board_col_to_matrix_idx(col);
	get_current_game_ptr()->board[pos.X][pos.Y_int] = PIECE;

}
Ejemplo n.º 5
0
/**
 * Function that the **whole** board as empty (the whole matrix)
 *
 * @return None
 * @date 2014-03-31
 * @author Triplet VIOPE 2014
 */
void board_set_empty(void){
	int i,j;
	int board_size = MAX_BOARDSIZE;

	for(i=0;i<board_size;i++){
		for(j=0;j<board_size;j++){
			get_current_game_ptr()->board[i][j] = EMPTY;
		}
	}
}
Ejemplo n.º 6
0
/**
 * Gets the content of the board in a specific row and column
 * The content is a char
 *
 * @v	board_size	"piece_on" is the char in that position
 * @return		The char in that position
 * @date		2014-04-14
 * @author		Triplet VIOPE 2014 (PT TEAM)
 */
char board_get_content_row_col(int row, char col){

	char piece_on;
	//matrix -> get_current_game->board[i][j];
	position_t pos;
	pos.X = board_row_to_matrix_idx(row);

	pos.Y_int = board_col_to_matrix_idx(col);
	piece_on = get_current_game_ptr()->board[pos.X][pos.Y_int]; //get_current_game_ptr()->board[i][j]

	return piece_on;
}
Ejemplo n.º 7
0
/**
 * Function to set the board size
 *
 * @v board_size value to use for board size
 * @return 0 if the specified board size is invalid, otherwise it returns
 * the board size
 * @date 2014-03-31
 * @author Triplet VIOPE 2014
 */
int board_set_size(const int board_size)
{
	if( ! board_is_valid_size(board_size) ){
		fprintf(stderr, "[Err] Invalid board size:%d\n", board_size);
		return 0;
	}

	/* Setting the board size */
	get_current_game_ptr()->board_rows = board_size;

	/* Clear board */
	board_set_empty();

	return board_size;
}
Ejemplo n.º 8
0
/**
 * Function that resets the data structs with invalid values
 * so that we can detect when we're using unitialized data members
 *
 * @return	void
 * @date	2014-03-31
 * @author	Triplet VIOPE 2014
 */
void reset_data_structs(void){
	game_t *game_ptr;
	int i;

	game_ptr = get_current_game_ptr();
	game_ptr->player_first = -1;
	game_ptr->board_columns = -1;
	game_ptr->board_rows = -1;
	game_ptr->game_mode = -1;

	/* Set the whole board as empty */
	board_set_empty();

	/* Deal with G_players */
	for(i=0;i<2;i++){
		player_reset(&(get_players_ptr()[i]));
	}
}
Ejemplo n.º 9
0
/**
 * Print the current board
 * @return None
 * @date 2014-04-21
 * @author  PL team -Triplet VIOPE 2014
 */
void board_print_raw(void){
	int i,j,k,l,m;
	int board_size = board_get_size();
	printf("[INFO] Board: %d x %d\n", board_size,board_size);
	if(board_size==BOARD_SMALL){
		printf("     GAME BOARD\n");}
	if(board_size==BOARD_MEDIUM){
		printf("           GAME BOARD\n");}
	if(board_size==BOARD_LARGE){
		printf("                     GAME BOARD\n");}

	for(i=0;i<board_size;i++){
		printf("    ");
		for(k=0;k<board_size;k++){
			printf("+---");}
		printf("+\n");
		if (i>8){
			printf(" %d ",i+1);
		}
		else{
			printf("  %d ",i+1);
		}
		for(j=0;j<board_size;j++){
			printf("| ");
			printf("%c ", get_current_game_ptr()->board[i][j]);
		}
		printf("|\n");
	}
	printf("    ");
	for(l=0;l<board_size;l++){
		printf("+---");}
	printf("+\n     ");
	char f=65;
	for(m=0;m<board_size;m++){
		printf(" %c  ",f);
		f=f+1;}
	printf("\n");
}
void test_reading_converting_validating()
{
    int counter = 1, check = 0;
    reset_data_structs();
    board_set_size(BOARD_MEDIUM);
    int dimension = board_get_size();
    position_t pos;

    while(counter == 1)
    {
        test_representation_matrix(get_current_game_ptr()->board, dimension);

        do
        {
            read_move(&pos);

            check = function_validate_move(pos);
        }
        while(check != 0);
        //arise the variable "int playNumber".
        //save in log
    }
}
Ejemplo n.º 11
0
/**
 * Getter function for the board size
 *
 * @return Current board size
 * @date 2014-03-31
 * @author Triplet VIOPE 2014
 */
int board_get_size(void){
	return get_current_game_ptr()->board_rows;
}
void loadLogs(int gameCounter)
{

    FILE *playLog;

    int playNumber;
    char dateExtended[32];
    char playerName[30];
    int dimension;
    int i;
    int moveX;
    char moveY;
    int lineCounter=0;
    int headLinesNumber=6;
    char logName[255];

    sprintf(logName, "data/logs/TripletsLog-%d.txt", gameCounter);

    lineCounter=get_file_lines(logName);

    lineCounter-=headLinesNumber;

    lineCounter++; // to add the last line which doesn't have /n !!


    playLog = fopen(logName, "rt");
    if(playLog == NULL)
    {
        printf("\n\tERR: Unable to read Log!");
    }
    else
    {
        gameCounter=0;
        dimension=0;
        fscanf(playLog, "--Triplets Log--\n");
        fscanf(playLog, "Game #%d\n", &gameCounter);
        fscanf(playLog, "Matrix Dimension: %dx%d\n", &dimension, &dimension);
        fscanf(playLog, "Started on: %s\n", dateExtended);

        board_set_size(dimension);
        board_set_empty();
        clearscr();
        board_print_raw();
        init_players();

        for (i=0; i<lineCounter; i++)
        {
            printf("\nPress any key to print next move...");
            readchar();
            clearscr();
            fscanf(playLog, "Player %s ; Play %d ; Move [%d][%c]\n", playerName, &playNumber, &moveX, &moveY);


            board_set_content_row_col(moveX, moveY);
            if (i==lineCounter-1)
            {
                finish_gamePL(get_current_game_ptr()->board);
            }
            board_print_raw();
            printf("\nPlayer Name: %s - Play Number: %d - Move: [%d][%c]\n",playerName, playNumber, moveX, moveY); // was just to test if it's reading right

            cmp.tmp=cmp.current_player_move;                   //swap current player
            cmp.current_player_move=cmp.previous_player_move;  //
            cmp.previous_player_move=cmp.tmp;

        }
        printf("\nWINNER: %s\a\n", playerName);
        printf("\nPress any key to go back to menu...");
        readchar();



    }

    fclose(playLog);

}