<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def writeDataTable(self, file, type):
 """ Writes agent data to an ReST table. The 'type' argument may be 'state', 'action' or 'reward'. """

        agents = self.experiment.agents
        numAgents = len(self.experiment.agents)

        colWidth = 8
        idxColWidth = 3

        sep = ("=" * idxColWidth) + " " + \
            ("=" * colWidth + " ") * numAgents + "\n"

        file.write(sep)

        # Table column headers.
        file.write("..".rjust(idxColWidth) + " ")
        for agent in agents:
            # The end of the name is typically the unique part.
            file.write(agent.name[-colWidth:].center(colWidth) + " ")
        file.write("\n")

        file.write(sep)

        # Table values.
        if agents:
            rows, _ = agents[0].history.getField( type ).shape
        else:
            rows, _ = (0, 0)

        for sequence in range( min(rows, 999) ):
            file.write( str(sequence + 1).rjust(idxColWidth) + " " )

            for agent in agents:
                field = agent.history.getField( type )
                # FIXME: Handle multiple state values.
                file.write("%8.3f " % field[sequence, 0])

            file.write("\n")

        file.write(sep)