public void updateBoard()
    {
        IPiece[][] pieces = board.getBoard();
        
        int maxlength = 0;
        for (int i = 0; i < pieces.length; i++)
            maxlength += pieces[i].length;        
        boolean[][] occupied = new boolean[3][maxlength];
        
        List<IPiece> movedPieces = new ArrayList<IPiece>();
        for (int i = 0; i < pieces.length; i++)
            for (int j = 0; j < pieces[i].length; j++)
            {
                Visual visual = visuals.get(pieces[i][j]);
                int y = i / 2;
                if (y == visual.y) // piece has not moved
                {
                    occupied[y][visual.x] = true;
                }
                else
                {
                    visual.y = y; // remember desired y
                    movedPieces.add(pieces[i][j]);
                }
                visual.gray = i % 2 == 1;
            }               
        
        for (IPiece piece : movedPieces)
        {
            Visual visual = visuals.get(piece);
            int x = 0;
            while (occupied[visual.y][x]) x++;
            visual.x = x;
            occupied[visual.y][x] = true;
        }
        repaint();
    }