Ejemplo n.º 1
0
op_result add_digit(int row, int col, int digit) {
	
	if(in_range(row)){
		if(in_range(col)){
			if(in_range(digit)){
				
				if(puzzle[row][col] != 0){
					return OP_OCCUPIED;
				}
				if((row_contains(row,digit))||(col_contains(col,digit))){
					return OP_ILLEGAL;
					
				}
				
				if(region_contains(row,col,digit)){
					return OP_ILLEGAL;
				}
				
				puzzle[row][col] = digit;		
				return OP_OK;
				
			}
		}
	}

	return OP_BADARGS ;
}
Ejemplo n.º 2
0
static void
draw_line (size_t line, size_t startcol, Window wp,
           size_t o, Region r, int highlight, size_t cur_tab_width)
{
  term_move (line, 0);

  /* Draw body of line. */
  size_t x, i, line_len = buffer_line_len (get_window_bp (wp), o);
  for (x = 0, i = startcol;; i++)
    {
      term_attrset (highlight && region_contains (r, o + i) ? FONT_REVERSE : FONT_NORMAL);
      if (i >= line_len || x >= get_window_ewidth (wp))
        break;
      char c = get_buffer_char (get_window_bp (wp), o + i);
      if (isprint (c))
        {
          term_addch (c);
          x++;
        }
      else
        {
          const char *s = make_char_printable (c, x, cur_tab_width);
          term_addstr (s);
          x += strlen (s);
        }
    }

  /* Draw end of line. */
  if (x >= term_width ())
    {
      term_move (line, term_width () - 1);
      term_attrset (FONT_NORMAL);
      term_addstr ("$");
    }
  else
    term_addstr (xasprintf ("%*s", (int) (get_window_ewidth (wp) - x), ""));
  term_attrset (FONT_NORMAL);
}
Ejemplo n.º 3
0
void configure(FILE *puzzle_file) {

	char line[5];//line buffer
	int row;
	int column;
	int value;
	int line_count = 0;
	
	while(( fgets(line,5,puzzle_file)) != NULL){
		
	
		row = line[0]-'0';
		column = line[1]-'0';
		value = line[2]-'0';
	
		
		if(!in_range(row) || !in_range(column) || !in_range(value)){
			printf("Illegal format in configuration file at line %d ", line_count);
			exit(1);
		}
	
		if((puzzle[row][column] != 0)||(row_contains(row,value))||(col_contains(column,value))||(region_contains(row,column,value))){
			printf("Illegal placement in configuration file at line %d ",line_count);
			exit(1);
		}
		
	
		
	
		puzzle[row][column] = value;
		fixed[row][column] = TRUE;	
		line_count += 1;
	}

}