{
  This example demonstrates how a Turn Right player can be made
  Turn Right is the CodeCup game 2006 (www.codecup.nl)
  The use of this file and/or ideas is not compulsory
  Left to do: three TODOs
  Written by Willem van der Vegt; adapted by Marcel Vlastuin
  Use Caia to play Turn Right games (and more...) at your own house
  Success and a lot of joy in the contest!
}

program turn_right;

type entry=(black,white,empty); {different entries for cells}

var board:      array['a'..'f','1'..'6'] of entry; {game board}
    movenumber: integer;                           {#move to be played}
    maxcorners: integer;                           {maximum # of corners}
    Am_I_White: boolean;                           {my color}
    My_Turn:    boolean;                           {is it my turn}
    line:       string[255];                       {for input and output}
    row,col:    char;                              {to store a move}
    color:      array[boolean] of entry;           {colors of stones}

  procedure StopTurnRight; {called after receiving an x}
  begin
    halt(0)
  end;

  procedure ProcessMoveInLine;
  begin
    if line[1]='x' then StopTurnRight;
    col:=line[1];
    row:=line[2];
    board[col,row]:=color[not Am_I_White]
  end;

  procedure CalculateAndProcessMove;
  begin  
    {TODO: CALCULATE AND STORE THE BEST MOVE IN col AND row USING board[,]}
    line:=col+row;
    board[col,row]:=color[Am_I_White] {process the move for yourself}
  end;

  procedure InitTurnRight;
  begin
    for col:='a' to 'f' do for row:='1' to '6' do board[col,row]:=empty;
    readln(line);
    if line='Start' then
    begin
      Am_I_White:=true;
      movenumber:=1
    end else
    begin
      Am_I_White:=false;
      ProcessMoveInLine;
      movenumber:=2
    end;
    My_Turn:=true
  end;

  procedure PerformBlackLastMove;
  begin
    col:='a';
    row:='1';
    while board[col,row]<>empty do
    begin
      if row='6' then
      begin
        inc(col);
        row:='1'
      end else inc(row)
    end;
    if My_Turn then board[col,row]:=color[Am_I_White]
               else board[col,row]:=color[not Am_I_White];
    movenumber:=1
  end;

  procedure ProcessSnakeWithinLine;
  begin
    {TODO: TURN THE SNAKE WITHIN line CLOCKWISE IN board[,]}
  end;

  procedure CalculateAndProcessSnake;
  begin
    {TODO: CALCULATE AND STORE THE BEST SNAKE
           IN line USING maxcorners AND board[,]}
    ProcessSnakeWithinLine
  end;

begin
  InitTurnRight;
  while movenumber<36 do
  begin
    CalculateAndProcessMove;
    writeln(line);
    flush(output);
    inc(movenumber);
    My_Turn:=not My_Turn;
    if movenumber<36 then
    begin
      readln(line);
      ProcessMoveInLine;
      inc(movenumber);
      My_Turn:=not My_Turn
    end
  end;
  PerformBlackLastMove;
  repeat
    maxcorners:=7+movenumber div 2;
    if My_Turn then
    begin
      CalculateAndProcessSnake;
      writeln(line);
      flush(output)
    end else
    begin
      readln(line);
      if line='x' then StopTurnRight;
      ProcessSnakeWithinLine;
    end;
    inc(movenumber);
    My_Turn:=not My_Turn;
  until movenumber>26
end.


syntax highlighted by Code2HTML, v. 0.9.1