Commit 402d88aa authored by Seblu's avatar Seblu
Browse files

les blocks dans un hxx

parent 3a27c01a
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -2,7 +2,8 @@ bin_PROGRAMS=sudoku

sudoku_SOURCES=	src/sudoku.hh			\
		src/sudoku.cc			\
		src/grid.cc
		src/grid.cc			\
		src/block.hxx

CLEANFILES= *~ '\#*'

src/block.hxx

0 → 100644
+45 −0
Original line number Diff line number Diff line
#ifndef BLOCK_HXX_
# define BLOCK_HXX_

inline Block::Block()
{
  Block(0);
}

inline Block::Block(int value) {
  value_ = value;
  for (int i = 0; i < GRID_SIDE; ++i)
    forbidden_[i] = false;
}

inline bool Block::is_forbidden(int value) const {
  assert(value > 0 && value <= GRID_SIDE);
  return forbidden_[value];
}

inline int Block::value_get() const
{
  return value_;
}

inline void Block::set(int val)
{
  assert(val > 0 && val <= GRID_SIDE);
  value_ = val;
}

inline void Block::forbid(int val) {
  assert(val > 0 && val <= GRID_SIDE);
  if (val != value_)
    forbidden_[val - 1] = true;
}

inline std::ostream &operator<<(std::ostream &stream, const Block &blk) {
  if (blk.value_ == 0)
    stream << " ";
  else
    stream << blk.value_;
  return stream;
}

#endif
+4 −4
Original line number Diff line number Diff line
@@ -14,15 +14,15 @@ int Grid::load(const char *filename)
  fs.open(filename, std::fstream::in);
  if (!fs.is_open())
    return 0;
  for (int i = 0; i < GRID_SIDE; ++i)
    for (int j = 0; j < GRID_SIDE; ++j) {
  for (int y = 0; y < GRID_SIDE; ++y)
    for (int x = 0; x < GRID_SIDE; ++x) {
      fs >> std::dec >> val;
      if (val < 0 || val > 9) {
	std::cerr << "Invalid value in file: " << val << std::endl;
	exit(EXIT_LOADFAIL);
      }
      if (val > 0)
	pose(i, j, val);
	pose(x, y, val);
      //block_[i][j].set(val);
    }
  fs.close();
@@ -71,7 +71,7 @@ void Grid::print() const
	  for (k = l * 3 + 1; k <= l * 3 + 3; ++k)
	    if (block_[i][j].value_get() == k)
	      std::cout << "\033[0;32m" << k  << "\033[0m";
	    else if (block_[i][j].is_forbid(k))
	    else if (block_[i][j].is_forbidden(k))
	      std::cout << "\033[0;31m" << k  << "\033[0m";
	    else
	      std::cout << k;
+0 −7
Original line number Diff line number Diff line
@@ -30,10 +30,3 @@ int main(int argc, char *argv[])
  return found;
}
std::ostream &operator<<(std::ostream &stream, const Block &blk) {
  if (blk.value_ == 0)
    stream << " ";
  else
    stream << blk.value_;
  return stream;
}
+9 −23
Original line number Diff line number Diff line
@@ -21,29 +21,13 @@ enum {
class Block
{
public:
  Block() { Block(0); }
  Block(int value) {
    value_ = value;
    for (int i = 0; i < GRID_SIDE; ++i)
      forbidden_[i] = false;
  }
  bool is_forbidden(int value) const {
    assert(value > 0 && value <= GRID_SIDE);
    return forbidden_[value];
  }
  int value_get() const { return value_; }
  bool is_forbid(int v) const {
    assert(v > 0 && v <= GRID_SIDE);
    return forbidden_[v - 1];
  }
  void init(int val) { assert(val >= 0 && val <= GRID_SIDE); value_ = val; }
  void set(int val) { assert(val > 0 && val <= GRID_SIDE); value_ = val; }
  void forbid(int val) {
    assert(val > 0 && val <= GRID_SIDE);
    if (val != value_)
      forbidden_[val] = true;
  }
  friend std::ostream &operator<<(std::ostream &stream, const Block &blk);
  inline Block();
  inline Block(int val);
  inline bool is_forbidden(int val) const;
  inline int value_get() const;
  inline void set(int val);
  inline void forbid(int val);
  inline friend std::ostream &operator<<(std::ostream &stream, const Block &blk);
private:
  int value_;
  bool forbidden_[GRID_SIDE];
@@ -76,4 +60,6 @@ void Grid::print_line() const
  }
}

#include "block.hxx"

#endif