Sindarus/tsumegomaker

Create another Board or PhysicalBoard constructor that can take a string as parameter

Closed this issue · 4 comments

So that you can init a board in a fast way, to make testing easier

You cannot overload in ruby, so the only way to mimic this is to create a static method such as Board.new_from_string() that returns a Board object
But then, how do you build the Board object from within the static method ? Maybe with a special access mode such as "protected", we can create a setter for @board, that can be called from a static method, but not from outside the class, so as to not break the encapsulation principle.

I have tried and it seems like static methods are just regular functions, the only difference with regular functions is that they are called differently : A.static_method for example. So, a static method cannot call a protected method of its class. So this is not doable. Anyway, this feature wasn't mandatory, it'd just have made testing easier.

actually it was mandatory, because when you load a problem, a Board has to be created from the PhysicalBoard of the problem...

I solved the problem by allowing the default constructor of Board to take an "initial_physical_board" for argument. If you want to create a Board without creating a physical board first, use Board.new_from_scratch(:width, :height, :not_border)
See commit c633281