void solve(int board[], int current_row, int max){//Hail jesus of recursive faith, segfaults I don't want to throw
  //if the current row,
  //is to the max, yo
  if (current_row == max)
    //flip that sh*t and return it
    return;
  
  //Loop i through positions on the board,
  //Drop the for loop - the magic is in motion
  //Better be efficient like Ron Jeremy in Love Potion
  for (int i=0;i<max;i++){

    //Move the queen, like a pound of green
    board[current_row]=i;
    
    //Check the board, check that sh*t
    if (check_board(board,current_row)==1) 
      //pass that stack, solve the other bit
      solve(board,current_row+1,max);   

    //Smooth sailing like yours truly MC
    //The board be solved or all be hell
    //If I got to the end, it's time to tell
    if (current_row==max -1 ) 
      //Spark that sh*t, shout out to queens
      //if the haze is dutch and the board is clean
      if (check_board(board,max-1)==1 && board[max-1]!=-1){
	//send the solution, 
	//ain't no confusion
	print_board_solution(board,max);   
      }
  }

  //check yourself,
  //before you wreck yourself

  //Biggie tells it better, peace to his urn

  if (current_row==max -1 )
    board[current_row]=-1;
  return;  	

  //Spread the word it takes time to learn

  //Playin with C, you playin' with fire
  //It don't give a f*ck about what you desire
  //C shoots like my 9 in the jacket
  //Pull the trigger, my ni**** 
  //But don't you smack it
}
Exemple #2
0
/** The added word is invalid in term of position (horizontally) but it does not exist in the dictionary
*\author Abdallah
*/
void test_horizontal_invalid ()
{
	tile * board [max_rc] [max_rc];
	new_board(board);
	tile * board_prev [max_rc] [max_rc];
	new_board (board_prev);
	bag real_bag, inhand_bag;
	tile t1,t2, t3, t4;// tiles to be used for testing purposesone for the real bag and the other for hand
	real_bag = new_real_bag();//initializing the real bag
	inhand_bag = new_inhand_bag(&real_bag);// initializing the 7 tiles in posession of the player from the real bag
	


	//Testing horizontal "to"
	t1 = new_tile('t');
	t2 = new_tile('w');
	t3 = new_tile('o');
	t4 = new_tile ('x');
	board[7][7] = &t1;
	board[7][8] = &t2;
	board[7][9] = &t3;

	board[7][6] = &t4;
	display_board(board);
	display_bag (inhand_bag);

	char new_word [word_len];
	check_board ( board , board_prev , str , & temp_score);

}
inline void check_board_knight(int r, int c) {
    int knight[8][2] = {{-2, -1}, {-2, 1},
                        {-1, 2}, {1, 2},
                        {2, 1}, {2, -1},
                        {1, -2}, {-1, -2}};
    check_board(knight, 8, 1, r, c);
}
/**
* second play is tested over first play
* the second play adds a word that exists in the dictionary but is nor properly connected
*\author Abdallah
*/
void test_second_invalid2()
{
	tile * board [max_rc] [max_rc];
	new_board(board);
	tile * board_prev [max_rc] [max_rc];
	new_board (board_prev);
	tile t1,t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15;
	t1 = new_tile('h');
	t2 = new_tile('a');
	t3 = new_tile('s');
	t4 = new_tile ('r');
	t5 = new_tile('e');
	t6 = new_tile('m');
	t7 = new_tile('d');
	
	board_prev[7][7] = &t1;
	board_prev[8][7] = &t2;
	board_prev[9][7] = &t3;

	board[7][7] = &t1;
	board[8][7] = &t2;
	board[9][7] = &t3;

	board[6][1] = &t4;
	board[7][1] = &t5;
	board[8][1] = &t6;
	printf("Board before second play\n");
	display_board (board_prev);

	printf("Board after second play\n");
	display_board (board);

	check_board ( board , board_prev , str , &temp_score );
}
Exemple #5
0
/** The added word is valid in term of position (vertically) and exists in the dictionary
*\author Abdallah
*/
void test_vertical_valid ()
{
	tile * board [max_rc] [max_rc];
	new_board(board);
	tile * board_prev [max_rc] [max_rc];
	new_board (board_prev);
	bag real_bag, inhand_bag;
	tile t1,t2, t3, t4;// tiles to be used for testing purposesone for the real bag and the other for hand
	real_bag = new_real_bag();//initializing the real bag
	inhand_bag = new_inhand_bag(&real_bag);// initializing the 7 tiles in posession of the player from the real bag
	


	//Testing horizontal "to"
	t1 = new_tile('l');
	t2 = new_tile('o');
	t3 = new_tile('s');
	t4 = new_tile ('e');
	board[7][7] = &t1;
	board[8][7] = &t2;
	board[9][7] = &t3;

	board[10][7] = &t4;
	display_board(board);
	display_bag (inhand_bag);

	char new_word [word_len];
	check_board ( board , board_prev , str , & temp_score);
	printf("The word added to the board is %s\n",str [0] );
}
/**
* second play is tested over first play
* the second play adds 3 words to the board by amending tiles to the existing word to form 3 new words
*\author Abdallah
*/
void test_second_valid3()
{
	tile * board [max_rc] [max_rc];
	new_board(board);
	tile * board_prev [max_rc] [max_rc];
	new_board (board_prev);
	tile t1,t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15;
	t1 = new_tile('h');
	t2 = new_tile('a');
	t3 = new_tile('s');
	t4 = new_tile ('r');
	t5 = new_tile('e');
	t6 = new_tile('m');
	t7 = new_tile('d');
	
	board_prev[7][7] = &t1;
	board_prev[8][7] = &t2;
	board_prev[9][7] = &t3;

	board[7][7] = &t1;
	board[8][7] = &t2;
	board[9][7] = &t3;

	board[6][8] = &t4;
	board[7][8] = &t5;
	board[8][8] = &t6;
	printf("Board before second play\n");
	display_board (board_prev);

	printf("Board after second play\n");
	display_board (board);

	check_board ( board , board_prev , str , &temp_score );
	printf("Expected value : 21\nR(1)*2 + E(1) + M(3)*2 = 9\nH(4) + E (1) =5 \nA(1) + M(3)*2 = 7\n");
}
Exemple #7
0
void cmd_load(void)
{
  char data[MAXSTR]="";
  LoadEPD (token[1]);
  pgnloaded = 0;
  check_board();
  if (!ValidateBoard()) {
    SET (flags, ENDED);
    printf (_("Board is wrong!\n"));
  } else {
    /* Read EPD file and send contents to engine */
    FILE *epdfile = fopen( token[1], "r" );
    char epdline[MAXSTR]="";
    if ( epdfile == NULL ) {
      printf(_("Error reading file '%s'\n"), token[1] );
    } else {
      if ( fgets( epdline, MAXSTR, epdfile ) == NULL ) {
        printf(_("Error reading file '%s'\n"), token[1] );
      } else {
        strcpy( data, "setboard " );
        int i=0;
        while ( epdline[i] != '\n' ) {
          data[i+9] = epdline[i];
          ++i;
        }
        data[i+9] = '\0';
        SetDataToEngine( data );
        SetAutoGo( true );
      }
    }
  }
}
inline void check_board_king(int r, int c) {
    int king[8][2] = {{-1, -1}, {-1, 0},
                      {-1, 1}, {0, 1},
                      {1, 1}, {1, 0},
                      {1, -1}, {0, -1}};
    check_board(king, 8, 1, r, c);
}
Exemple #9
0
/**
* A word placed but not passing by the central square
* \author Abdallah
*/
void test_invalid4()
{
	tile * board [max_rc] [max_rc];
	new_board(board);
	tile * board_prev [max_rc] [max_rc];
	new_board (board_prev);
	bag real_bag, inhand_bag;
	tile t1,t2, t3, t4;// tiles to be used for testing purposesone for the real bag and the other for hand
	real_bag = new_real_bag();//initializing the real bag
	inhand_bag = new_inhand_bag(&real_bag);// initializing the 7 tiles in posession of the player from the real bag
	
	t1 = new_tile('g');
	t2 = new_tile('o');
	t3 = new_tile('o');
	t4 = new_tile ('d');
	
	board[7][8] = &t1;
	board[7][9] = &t2;
	board[7][10] = &t3;
	board[7][11] = &t4;
	display_board(board);
	display_bag (inhand_bag);

	char new_word [word_len];
	check_board ( board , board_prev , str , & temp_score);
printf("Invalid placement \n");
}
/**
* nth play where the board is in a valid state that can occur after one or more plays the added tiles are valid and pass by a triple word square
* \author Abdallah
*/
void test_nth_valid3()
{
	tile * board [max_rc] [max_rc];
	new_board(board);
	tile * board_prev [max_rc] [max_rc];
	new_board (board_prev);
	tile t1,t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15;
	t1 = new_tile('c');
	t2 = new_tile('l');
	t3 = new_tile('a');
	t8 = new_tile('n');
	t4 = new_tile ('o');
	t5 = new_tile('v');
	t6 = new_tile('a');
	t7 = new_tile('l');

	t9 = new_tile('o');
	t10 = new_tile ('n');
	
	board_prev[7][7] = &t1;
	board_prev[7][8] = &t2;
	board_prev[7][9] = &t3;
	board_prev[7][10] = &t8;
	board_prev[6][10] = &t4;
	board_prev[6][11] = &t5;
	board_prev[6][12] = &t6;
	board_prev[6][13] = &t7;
	


	board [7][7] = &t1;
	board [7][8] = &t2;
	board [7][9] = &t3;
	board [7][10] = &t8;
	board [6][10] = &t4;
	board [6][11] = &t5;
	board [6][12] = &t6;
	board [6][13] = &t7;

	board[7][13] = &t9;
	board[7][14] = &t10;

	printf("Board before second play\n");
	display_board (board_prev);

	printf("Board after second play\n");
	display_board (board);

	check_board ( board , board_prev , str , &temp_score );
	printf("Expected added score is 8\nL(1) + O (1) =2 \n( O(1) + N (1) )*3 = 6\n");
}
Exemple #11
0
/** The added word is valid in term of position (horizontally) exists in the dictionary
*\author Abdallah
*/
void test_horizontal_valid ()
{
	tile * board [max_rc] [max_rc];
	new_board(board);
	tile * board_prev [max_rc] [max_rc];
	new_board (board_prev);
	bag real_bag, inhand_bag;
	tile t1,t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15;
	real_bag = new_real_bag();//initializing the real bag
	inhand_bag = new_inhand_bag(&real_bag);// initializing the 7 tiles in posession of the player from the real bag
    //tested word:holocrystalline, longest possible (15 letters)
	t1 = new_tile('h');
	t2 = new_tile('o');
	t3 = new_tile('l');
	t4 = new_tile ('o');
	t5 = new_tile('c');
	t6 = new_tile('r');
	t7 = new_tile('y');
	t8 = new_tile ('s');
	t9 = new_tile('t');
	t10 = new_tile('a');
	t11= new_tile('l');
	t12= new_tile ('l');
	t13= new_tile ('i');
	t14= new_tile ('n');
	t15= new_tile ('e');
	board[7][0] = &t1;
	board[7][1] = &t2;
	board[7][2] = &t3;
	board[7][3] = &t4;
	board[7][4] = &t5;
	board[7][5] = &t6;
	board[7][6] = &t7;
	board[7][7] = &t8;
	board[7][8] = &t9;
	board[7][9] = &t10;
	board[7][10] = &t11;
	board[7][11] = &t12;
	board[7][12] = &t13;
	board[7][13] = &t14;
	board[7][14] = &t15;
	display_board(board);
	display_bag (inhand_bag);

	char new_word [word_len];
	check_board ( board , board_prev , str , & temp_score );
	printf("The word added to the board is %s\n",str [0] );

}
Exemple #12
0
/** The player tries to play the first turn without adding any tiles, a warning message is displayed to ask him to add a tile passing through the center
*\author Abdallah
*/
void test_empty()
{
	tile * board [max_rc] [max_rc];
	new_board(board);
	tile * board_prev [max_rc] [max_rc];
	new_board (board_prev);
	bag real_bag, inhand_bag;
	real_bag = new_real_bag();//initializing the real bag
	inhand_bag = new_inhand_bag(&real_bag);// initializing the 7 tiles in posession of the player from the real bag
	display_board(board);
	display_bag (inhand_bag);

	char new_word [word_len];
	check_board ( board , board_prev , str , & temp_score);
	printf("Invalid placement; no tiles \n");
}
Exemple #13
0
int BT_Moderator :: check_invalid(BT_Player player_1, BT_Player player_2){
	if (check_board(player_1, 0) == true || check_board(player_2, 1) == true) {
		if (check_board(player_1, 0) == true && check_board(player_2, 1) == false) {
			return 0;
		}else if (check_board(player_1, 0) == false && check_board(player_2, 1) == true) {
			return 1;
		}else{
			return 2;
		}
	}
	return 3;
}
void test_second_valid ()
{
	tile * board [max_rc] [max_rc];
	new_board(board);
	tile * board_prev [max_rc] [max_rc];
	new_board (board_prev);
	tile t1,t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15;
	t1 = new_tile('f');
	t2 = new_tile('i');
	t3 = new_tile('l');
	t4 = new_tile ('l');
	t5 = new_tile('e');
	t6 = new_tile('d');
	t7 = new_tile('y');
	t8 = new_tile ('s');
	t9 = new_tile('t');
	t10 = new_tile('a');
	t11= new_tile('l');
	t12= new_tile ('l');
	t13= new_tile ('i');
	t14= new_tile ('n');
	t15= new_tile ('e');
	board_prev[7][7] = &t1;
	board_prev[7][8] = &t2;
	board_prev[7][9] = &t3;
	board_prev[7][10] = &t4;

	board[7][7] = &t1;
	board[7][8] = &t2;
	board[7][9] = &t3;
	board[7][10] = &t4;

	board[7][11] = &t5;
	board[7][12] = &t6;
	printf("Board before second play\n");
	display_board (board_prev);

	printf("Board after second play\n");
	display_board (board);

	check_board ( board , board_prev , str , &temp_score );
	printf("Expected added value : 11\nF(4) + I(1) + L (1) + L (1) +E (1)*2 + D (2) \n");
	temp_score = 0;

}
/**
* nth play where the board is in a valid state that can occur after one or more plays the added tiles are valid and pass by a double word square
* \author Abdallah
*/
void test_nth_valid2()
{
	
	tile * board [max_rc] [max_rc];
	new_board(board);
	tile * board_prev [max_rc] [max_rc];
	new_board (board_prev);
	tile t1,t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15;
	t1 = new_tile('c');
	t2 = new_tile('l');
	t3 = new_tile('a');
	t8 = new_tile('n');
	t4 = new_tile ('n');
	t5 = new_tile('o');
	t6 = new_tile('n');
	t7 = new_tile('e');
	
	board_prev[7][7] = &t1;
	board_prev[7][8] = &t2;
	board_prev[7][9] = &t3;
	board_prev[7][10] = &t8;
	board_prev[8][10] = &t5;
	board_prev[9][10] = &t6;
	


	board [7][7] = &t1;
	board [7][8] = &t2;
	board [7][9] = &t3;
	board [7][10] = &t8;
	board[8][10] = &t5;
	board[9][10] = &t6;
	

	board[10][10] = &t7;

	printf("Board before second play\n");
	display_board (board_prev);

	printf("Board after second play\n");
	display_board (board);

	check_board ( board , board_prev , str , &temp_score );
	printf("Expected added score is 8\n");
}
Exemple #16
0
int main()
{
    initialize();
    int tests = 1000;
    int passed = 0;
    fast_srandom(time(0));
    for (int i = 0; i < tests; i++) {
        board_t *b = new board_t;
        int size = fast_random(max_size - 4) + 5;
        empty_board(b, size);
        int steps = 0;
        bool failed = false;
        while (true) {
            stone_t color = steps % 2 == 0 ? STONE_BLACK : STONE_WHITE;
            index_t pos = gen_move(b, color);
            if (pos < 0)
                break;
            if (!is_legal_move(b, pos, color)) {
                failed = true;
                break;
            }
            if (pos >= 0) {
                put_stone(b, pos, color);
                if (!check_board(b)) {
                    failed = true;
                    break;
                }
            }
            steps++;
        }
        delete b;
        if (failed) {
            printf("[F]");
        } else {
            printf("[%d]", steps);
            passed++;
        }
    }
    printf("\n");
    printf("Passed %d out of %d random tests\n", passed, tests);

    return passed == tests ? 0 : 1;
}
/**
* second play is tested over first play
* the second play adds 4 words to the board by amending tiles to the existing word to form 4 new words
* this give me a huge error but from the analysis I can assume it is from the part when the the char is changed to int and vice versa because if the tenth is changed from 1 to 0 the answer would be correct
*\author Abdallah
*/
void test_second_valid4()
{
	tile * board [max_rc] [max_rc];
	new_board(board);
	tile * board_prev [max_rc] [max_rc];
	new_board (board_prev);
	tile t1,t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15;
	t1 = new_tile('h');
	t2 = new_tile('a');
	t3 = new_tile('i');
	t8 = new_tile('r');
	t4 = new_tile ('r');
	t5 = new_tile('e');
	t6 = new_tile('m');
	t7 = new_tile('s');
	
	board_prev[7][7] = &t1;
	board_prev[7][8] = &t2;
	board_prev[7][9] = &t3;
	board_prev[7][10] = &t8;


	board [7][7] = &t1;
	board [7][8] = &t2;
	board [7][9] = &t3;
	board [7][10] = &t8;

	board[8][6] = &t4;
	board[8][7] = &t5;
	board[8][8] = &t6;
	board[8][9] = &t7;

	printf("Board before second play\n");
	display_board (board_prev);

	printf("Board after second play\n");
	display_board (board);

	check_board ( board , board_prev , str , &temp_score );
	printf("Expected value is 10 + 5 + 7 + 2 = 24 \n");
}
Exemple #18
0
/* Main function : Does the steps listed in the introduction */
int main (int argc, char **argv) {
	char *positions, i;
	limit = atoi (argv[1]);

	pri_diag = (char *) calloc (limit * 2, sizeof (char));
	sec_diag = (char *) calloc (limit * 2, sizeof (char));

	while (1) {
		re_init_board ();

		if (!(positions = get_next_permute ())) break;

		if (check_board (positions)) {
			for (i = 0; i < limit; i++)
				printf ("%c%d ", i+'a', positions[i] - 'a' + 1);
			break;
			putchar ('\n');
		}
	}

	return 0;
}
inline void check_board_pawn(int r, int c, int sign) {
    int pawn[2][2] = {{1, -1}, {1, 1}};

    check_board(pawn, 2, sign, r, c);
}