Re: initializing an array of user-defined data types
- From: Bart Vandewoestyne <MyFirstName.MyLastName@xxxxxxxxxx>
- Date: Thu, 29 Nov 2007 09:15:53 GMT
On 2007-11-28, Bart Vandewoestyne <MyFirstName.MyLastName@xxxxxxxxxx> wrote:
I have a rank 2 array of a user-defined type as follows:
type(piece), dimension(:,:), allocatable, private :: board
After allocating it, I want to initialize it so that after
initialization, I can check whether board(i,j) contains a piece
or not.
I've tried things like
board = NULL
... assign some pieces to board positions and leave others empty ...
if (board(i,j) == NULL) then
... do something ...
end if
but that doesn't seem to work.
What is the proper way to do this?
Guys,
Thanks for all your suggestions and hints. The reason why I was
asking this is because I am implementing a backtracking program
for the Eternity II puzzle: http://www.eternityii.com
I'm doing this just for fun and to improve my skills of
transforming a given problem into Fortran 95 code. And you never
know, perhaps my program finds the 2 million dollar solution! :-)
Reading all the suggestions that people gave me in this thread, I
am currently modelling the problem as follows:
The main board consists of `cells' (or `board positions', `locations'):
type(cell), dimension(:,:), allocatable, private :: board
Each cell has an x and y coordinate, a color at each edge, an
indicator of whether it's free or not and if there is a piece at
this location, i also attach that piece:
type, private :: cell
integer(kind=i2b) :: x, y
integer(kind=i2b) :: northcolor, eastcolor, southcolor, westcolor
logical :: free
type(piece) :: piece
end type cell
Next to the board with cells, I also have the individual pieces that I
can place on the board. Each piece has a number, a color at each edge,
an indicator whether it is a starter piece or a hint piece and a rotation:
type, public :: piece
integer(kind=i2b) :: number
integer(kind=i2b) :: northcolor, eastcolor, southcolor, westcolor
logical :: starter_piece, hint_piece
integer(kind=i2b) :: rotation
end type piece
Feel free to share me your comments. Comments on the choice for the names
of the variables etc... is also welcome as I prefer easily readable code.
As soon as I have clean code that works for the 4x4 example puzzle on the
Eternity II website, I will put it online so that others can comment on it
and hopefully we can then even speed it up... or even parallellize! :-)
Regards,
Bart
--
"Share what you know. Learn what you don't."
.
- References:
- initializing an array of user-defined data types
- From: Bart Vandewoestyne
- initializing an array of user-defined data types
- Prev by Date: Re: Re-ordering columns or rows of an array efficiently
- Next by Date: Re: Fortran Error Reporting Requirements
- Previous by thread: Re: initializing an array of user-defined data types
- Next by thread: Re-ordering columns or rows of an array efficiently
- Index(es):
Relevant Pages
|