anchor.diff:  %% ----------------------------------------------------------------------
   %% API functions
   %% ----------------------------------------------------------------------
  -
  -%% @doc Create a chess board with the all chessmans at their start point.
  --spec new() -> board().
  -new() ->
  -    {
  -     %%  a       b        c       d       e       f        g       h
  -     {?brook,?bknight,?bbishop,?bqueen,?bking,?bbishop,?bknight,?brook}, % 8
  -     {?bpawn,?bpawn,  ?bpawn,  ?bpawn, ?bpawn,?bpawn,  ?bpawn,  ?bpawn}, % 7
  -     {?empty,?empty,  ?empty,  ?empty, ?empty,?empty,  ?empty,  ?empty}, % 6
  -     {?empty,?empty,  ?empty,  ?empty, ?empty,?empty,  ?empty,  ?empty}, % 5
  -     {?empty,?empty,  ?empty,  ?empty, ?empty,?empty,  ?empty,  ?empty}, % 4
  -     {?empty,?empty,  ?empty,  ?empty, ?empty,?empty,  ?empty,  ?empty}, % 3
  -     {?wpawn,?wpawn,  ?wpawn,  ?wpawn, ?wpawn,?wpawn,  ?wpawn,  ?wpawn}, % 2
  -     {?wrook,?wknight,?wbishop,?wqueen,?wking,?wbishop,?wknight,?wrook}  % 1
  -     %%  a       b        c       d       e       f        g       h
  -    }.
   
   %% @doc Do the next move.
   -spec move(History :: echessd_game:history(), Ply :: echessd_game:ply()) ->
  
positive.code:               end
        end, all_cells()).
  
  %% @doc Make the chessman move according to the chessman type.
  %% No additional checks will be performed (e.g is king checked).
  -spec move_unsafe(Board :: board(),
                    Ply :: echessd_game:ply() |
                           echessd_game:ply_coords()) ->
                           {NewBoard :: board(),
                            Capture :: echessd_game:entry()}.
  move_unsafe(Board, Ply) ->
      {I1, I2, Tail} = ply_dec(Ply),
      move_unsafe(Board, I1, I2, Tail).
  
  %% @private
  %% @doc Helper for the can_move/1 fun.
  -spec can_move(Board :: board(), Color :: echessd_game:color(),
                 History :: echessd_game:history()) -> boolean().
  can_move(Board, Color, History) ->
      lists:any(
        fun(I1) ->
                case getcell(Board, I1) of
                    {Color, _ChessmanType} ->
                        lists:any(
                          fun(I2) ->
                                  is_valid(Board, I1, I2, History)
                          end, hint_for_cell_unsafe(Board, I1, History));
                    _ -> false
                end
        end, all_cells()).
  
  %% @doc Turn the board at 180 degrees.
  -spec transpose(Board :: board()) -> TransposedBoard :: board().
  transpose(Board) ->
      list_to_tuple(
        lists:reverse(
          [list_to_tuple(
             lists:reverse(
               tuple_to_list(R))) || R <- tuple_to_list(Board)])).
  
  %% ----------------------------------------------------------------------
  %% Internal functions
  %% ----------------------------------------------------------------------
  
  %% @doc Just change chessman locations on the chess board.
  -spec move_chessman(Board :: board(),
                      SrcCoord :: coord(), DstCoord :: coord(),
                      SrcEntry :: echessd_game:entry(),
                      DstEntry :: echessd_game:entry()) ->
                             {NewBoard :: board(),
                              Capture :: echessd_game:entry()}.
  move_chessman(Board, SrcCoord, DstCoord, SrcEntry, DstEntry) ->
      {setcell(setcell(Board, SrcCoord, ?empty), DstCoord, SrcEntry),
       DstEntry}.
  
  %% @doc Return game status.
  -spec status(Board :: board(), Color :: echessd_game:color(),
               History :: echessd_game:history()) ->
                      GameStatus :: echessd_game:status().
  status(Board, Color, History) ->
      case can_move(Board, Color, History) of
          true ->
              ?gs_alive;
          false ->
              KingCoord = whereis_the_king(History, Color),
              case is_cell_attacked(Board, KingCoord, not_color(Color)) of
                  false ->
                      ?gs_draw_stalemate;
                  _ ->
                      ?gs_checkmate
              end
      end.
  
  %% @doc Return chess board with chessmans in their current positions,
  %% a list of all captured chessmans and the color of the next move.
  -spec from_scratch(History :: echessd_game:history()) ->
  
negative.code:         true ->
               ?black
       end}.
  
  %% @doc Turn the board at 180 degrees.
  -spec transpose(Board :: board()) -> TransposedBoard :: board().
  transpose(Board) ->
      list_to_tuple(
        lists:reverse(
          [list_to_tuple(
             lists:reverse(
               tuple_to_list(R))) || R <- tuple_to_list(Board)])).
  
  %% ----------------------------------------------------------------------
  %% Internal functions
  %% ----------------------------------------------------------------------
  
  %% @doc Create a chess board with the all chessmans at their start point.
  -spec new() -> board().
  new() ->
      {
       %%  a       b        c       d       e       f        g       h
       {?brook,?bknight,?bbishop,?bqueen,?bking,?bbishop,?bknight,?brook}, % 8
       {?bpawn,?bpawn,  ?bpawn,  ?bpawn, ?bpawn,?bpawn,  ?bpawn,  ?bpawn}, % 7
       {?empty,?empty,  ?empty,  ?empty, ?empty,?empty,  ?empty,  ?empty}, % 6
       {?empty,?empty,  ?empty,  ?empty, ?empty,?empty,  ?empty,  ?empty}, % 5
       {?empty,?empty,  ?empty,  ?empty, ?empty,?empty,  ?empty,  ?empty}, % 4
       {?empty,?empty,  ?empty,  ?empty, ?empty,?empty,  ?empty,  ?empty}, % 3
       {?wpawn,?wpawn,  ?wpawn,  ?wpawn, ?wpawn,?wpawn,  ?wpawn,  ?wpawn}, % 2
       {?wrook,?wknight,?wbishop,?wqueen,?wking,?wbishop,?wknight,?wrook}  % 1
       %%  a       b        c       d       e       f        g       h
      }.
  
  %% @doc Just change chessman locations on the chess board.
  -spec move_chessman(Board :: board(),
                      SrcCoord :: coord(), DstCoord :: coord(),
                      SrcEntry :: echessd_game:entry(),
                      DstEntry :: echessd_game:entry()) ->
                             {NewBoard :: board(),
                              Capture :: echessd_game:entry()}.
  move_chessman(Board, SrcCoord, DstCoord, SrcEntry, DstEntry) ->
      {setcell(setcell(Board, SrcCoord, ?empty), DstCoord, SrcEntry),
       DstEntry}.
  
  %% @doc Return game status.
  -spec status(Board :: board(), Color :: echessd_game:color(),
               History :: echessd_game:history()) ->
                      GameStatus :: echessd_game:status().
  status(Board, Color, History) ->
      case can_move(Board, Color, History) of
          true ->
              ?gs_alive;
          false ->
              KingCoord = whereis_the_king(History, Color),
              case is_cell_attacked(Board, KingCoord, not_color(Color)) of
                  false ->
                      ?gs_draw_stalemate;
                  _ ->
                      ?gs_checkmate
              end
      end.
  
  %% @doc Helper for the can_move/1 fun.
  -spec can_move(Board :: board(), Color :: echessd_game:color(),
                 History :: echessd_game:history()) -> boolean().
  can_move(Board, Color, History) ->
      lists:any(
        fun(I1) ->
                case getcell(Board, I1) of
                    {Color, _ChessmanType} ->
                        lists:any(
                          fun(I2) ->
                                  is_valid(Board, I1, I2, History)
                          end, hint_for_cell_unsafe(Board, I1, History));
                    _ -> false
                end
        end, all_cells()).
  
  %% @doc Make the chessman move according to the chessman type.
  %% No additional checks will be performed (e.g is king checked).
  -spec move_unsafe(Board :: board(),
                    Ply :: echessd_game:ply() |
                           echessd_game:ply_coords()) ->
                           {NewBoard :: board(),
                            Capture :: echessd_game:entry()}.
  move_unsafe(Board, Ply) ->
      {I1, I2, Tail} = ply_dec(Ply),
      move_unsafe(Board, I1, I2, Tail).
  
  %% @doc Helper for the move_unsafe/2 fun.
  -spec move_unsafe(Board :: board(), SrcCoord :: coord(),
  