Re: initializing an array of user-defined data types



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."
.



Relevant Pages

  • Re: why do loop control variables have to be local ? <- problem
    ... > can initialize, process, or display any cell you want. ... Now I have to declare local loop control variables everywhere! ... > displaying all the fields solely via the SingleLoop interface. ...
    (alt.comp.lang.borland-delphi)
  • Re: How to determine the angle within hexagonal spiral?
    ... We note that the number of points added at each 360 rotation just increases ... If a number is given in cell A1, I would like to determine the angle based ... and the crowning place of kings ...
    (microsoft.public.excel.misc)
  • Thank everyone very much for any suggestions
    ... We note that the number of points added at each 360 rotation just increases ... If a number is given in cell A1, I would like to determine the angle based ... and the crowning place of kings ...
    (microsoft.public.excel.misc)
  • Re: Parsing and Counting Matches - My State Table.xls (0/1)
    ... ' Search for occurance in a Cell of a string found in a specific Cell ... ' Need nested loops to traverse both the Search Cell and the String Cells. ... Dim CellString As String 'Cell to search ... CellRow = 2 ' Initialize Cell Row ...
    (microsoft.public.excel)
  • Re: Lithospheric drip in Basin and Range
    ... It beats me when I see guys still trying to promote these 'convection ... cell' ideas when it is just easier to step back,take a wider view of ... No one denies that rotation is important. ... rotation,the crust is generated symmmetrically off the central ridge. ...
    (sci.geo.geology)