home *** CD-ROM | disk | FTP | other *** search
- #define CONTEST_C
- #include "Contest.h"
- #undef CONTEST_C
-
-
- #if defined(__MWERKS__)
- #pragma segment __%Main
- #else
- #pragma segment Main
- #endif
-
-
- void
- MoveToContestNotation (MovePtr source, CoordinatePtr destination, BoardPtr board)
- {
- if (source[1] != 0)
- FlicheMoveToContestNotation (source, destination);
- else if (board->field[Neighbour (source[0], source[3])] == board->field[source[0]])
- NormalMoveToContestNotation (source, destination, board);
- else
- SimpleMoveToContestNotation (source, destination);
- }
-
-
-
- ///void
- //ContestNotationToMove (CoordinatePtr source, MovePtr destination)
- //{
- // if (source[3] == '-') // separator instead of head, so a simple move
- // ContestNotationToSimpleMove (source, destination);
- // else if (ContestNotationLineDirection (source) == ContestNotationMoveDirection (source))
- // ContestNotationToNormalMove (source, destination);
- // else /* only fliche moves remain */
- // ContestNotationToFlicheMove (source, destination);
- //}
-
-
-
- void
- FieldToCoordinate (Field f, CoordinatePtr cp)
- {
- char h = 0, v = 0;
-
- if (f > 0 && f <= 5) { h = (f - 1); v = 8; }
- else if (f <= 11) { h = (f - 6); v = 7; }
- else if (f <= 18) { h = (f - 12); v = 6; }
- else if (f <= 26) { h = (f - 19); v = 5; }
- else if (f <= 35) { h = (f - 27); v = 4; }
- else if (f <= 43) { h = (f - 36); v = 3; }
- else if (f <= 50) { h = (f - 44); v = 2; }
- else if (f <= 56) { h = (f - 51); v = 1; }
- else if (f <= 61) { h = (f - 57); v = 0; }
-
- cp[0] = 'a' + v;
- cp[1] = '1' + h;
- }
-
-
-
- Field
- CoordinateToField (CoordinatePtr coord)
- {
- Assert (coord[0] >= 'a' && coord[0] <= 'i', ILLEGAL_PARAMETER);
- Assert (coord[1] >= '0' && coord[1] <= '9', ILLEGAL_PARAMETER);
-
- switch (coord[0])
- {
- case 'a':
- return coord[1] - '0' + 0;
- case 'b':
- return coord[1] - '0' + 5;
- case 'c':
- return coord[1] - '0' + 11;
- case 'd':
- return coord[1] - '0' + 18;
- case 'e':
- return coord[1] - '0' + 26;
- case 'f':
- return coord[1] - '0' + 35;
- case 'g':
- return coord[1] - '0' + 43;
- case 'h':
- return coord[1] - '0' + 50;
- case 'i':
- return coord[1] - '0' + 56;
- default:
- return 0;
- }
- }
-
-
-
- void
- SimpleMoveToContestNotation (MovePtr source, CoordinatePtr destination)
- {
- Coordinate oldtail, newtail;
-
- FieldToCoordinate (source[0], oldtail);
- FieldToCoordinate (Neighbour (source[0], source[3]), newtail);
-
- destination[0] = oldtail[0];
- destination[1] = oldtail[1];
- destination[2] = '-';
- destination[3] = newtail[0];
- destination[4] = newtail[1];
- destination[5] = '\0';
- }
-
-
-
- void
- NormalMoveToContestNotation (MovePtr source, CoordinatePtr destination, BoardPtr board)
- {
- Coordinate oldtail, oldhead, newtail;
- Field current;
-
- FieldToCoordinate (source[0], oldtail);
-
- /* find old head */
-
- for ( current = source[0];
- board->field[current] == board->field[Neighbour(current, source[3])];
- current = Neighbour (current, source[3])
- )
- ;
-
- FieldToCoordinate (current, oldhead);
-
- // find new tail
-
- FieldToCoordinate (Neighbour(source[0], source[3]), newtail);
-
- destination[0] = oldtail[0];
- destination[1] = oldtail[1];
- destination[2] = oldhead[0];
- destination[3] = oldhead[1];
- destination[4] = '-';
- destination[5] = newtail[0];
- destination[6] = newtail[1];
- destination[7] = '\0';
- }
-
-
-
- void
- FlicheMoveToContestNotation (MovePtr source, CoordinatePtr destination)
- {
- Coordinate oldtail, oldhead, newtail;
-
- // The problem here is the 'always forward' convention, which is different from mine
-
- short flicheDirection = Direction (source[0], source[1]);
- short difference = (source[3] - flicheDirection + 6) % 6;
-
- Assert (difference != 0 && difference != 3, ILLEGAL_PARAMETER); // that's a straight move!
-
- if (difference == 1 || difference == 5) // the fliche move is 'forward'
- {
- FieldToCoordinate (source[0], oldtail);
- FieldToCoordinate (source[2] ? source[2] : source[1], oldhead);
- FieldToCoordinate (Neighbour (source[0], source[3]), newtail);
- }
- else // the fliche move is 'backward'
- {
- /* This means the fliche should be read backward */
-
- FieldToCoordinate (source[2] ? source[2] : source[1], oldtail);
- FieldToCoordinate (source[0], oldhead);
- FieldToCoordinate (Neighbour (source[2] ? source[2] : source[1], source[3]), newtail);
- }
- destination[0] = oldtail[0];
- destination[1] = oldtail[1];
- destination[2] = oldhead[0];
- destination[3] = oldhead[1];
- destination[4] = '-';
- destination[5] = newtail[0];
- destination[6] = newtail[1];
- destination[7] = '\0';
- }
-
-
-
- short
- ContestNotationDirection (CoordinatePtr tail, CoordinatePtr head)
- {
- Field from = CoordinateToField (tail),
- to = CoordinateToField (head);
- short d;
-
- if (Neighbours (from, to)) // easy: line of 2 balls
- return Direction (from, to);
-
- // tail and head are not neighbours, so this must be a line of three balls.
-
- for (d = right; d <= topright; d++)
- if (Neighbour (Neighbour (from, d), d) == to)
- return d;
-
- return down;
- }
-
-
-
- short
- ContestNotationLineDirection (CoordinatePtr notation)
- {
- Assert (notation[2] != '-', ILLEGAL_PARAMETER);
- Assert (notation[4] == '-', ILLEGAL_PARAMETER);
-
- return ContestNotationDirection (notation, notation + 2);
- }
-
-
-
- short
- ContestNotationMoveDirection (CoordinatePtr notation)
- {
- return ContestNotationDirection (notation, notation + (notation[2] == '-' ? 3 : 5));
- }
-
-
-
- //void
- //ContestNotationToSimpleMove (CoordinatePtr source, MovePtr destination)
- //{
- //#pragma unused (destination)
- //
- // Assert (source[2] == '-', ILLEGAL_PARAMETER);
- //}
- //
- //
- //
- //void
- //ContestNotationToNormalMove (CoordinatePtr source, MovePtr destination)
- //{
- //#pragma unused (destination)
- //
- // Assert (ContestNotationLineDirection (source) == ContestNotationLineDirection (source), INTERNAL_ERROR);
- //}
- //
- //
- //
- //void
- //ContestNotationToFlicheMove (CoordinatePtr source, MovePtr destination)
- //{
- //#pragma unused (destination)
- //
- // Assert (ContestNotationLineDirection (source) != ContestNotationLineDirection (source), INTERNAL_ERROR);
- //}
- //
-