//***********************************************************
//*
//* File:           PlayerWrapper.java
//* Author:         Abhinav Kamra
//* Contact:        kamra-at-cs.columbia.edu
//* Update:         11.9.2002
//*
//* Description:    Player wrapper class for the CookieCutter
//*                 package.
//*
//***********************************************************

package CookieCutter;

import java.util.*;
import java.io.Serializable;

public final class PlayerWrapper implements Serializable, IFCPlayer {

    double      _score;
    double      _totaltime;
    IFCPlayer   _player;
    Class       _class;
    CookieCutter   _cookiecutter;
    String      _name;

    PlayerWrapper(Class __class) throws Exception {
        _class = __class;
    }

    public void register(CookieCutter __cookiecutter) throws Exception {
        _cookiecutter = __cookiecutter;
        _player = (IFCPlayer) _class.newInstance();
        _player.register(_cookiecutter);
        _name = _player.name();
    }

    public void register(CookieCutter __cookiecutter, IFCPlayer __player) throws Exception {
        _cookiecutter = __cookiecutter;
        _player = __player;
        _player.register(_cookiecutter);
        _class = _player.getClass();
        _name = _player.name();
    }

    public String name() throws Exception {
        return _name;
    }

    public boolean interactive() throws Exception {
        return _player.interactive();
    }

    public Class playerClass() throws Exception {
        return _class;
    }

    public Move[] moves() throws Exception {
        try {
            Move[] moves = _player.moves();
            int _MAX = moves.length;
            char type;

/*
            for (int i=0; i < _MAX; i++) {
                type = moves[i].type();
                if (type != _CROTATION && type != _CROTATION_ARBITRARY && type != _CTRANSLATION) {
                    throw new Exception("Error:  Unknown Move Type: " + type);
                }
                if ((type == _CROTATION || type == _CROTATION_ARBITRARY) && Math.abs(moves[i].param1()) > 2 * Math.PI) {
                    throw new Exception("Error:  Rotation Value Out Of Bounds (> 2 Pi Radians): " + moves[i].param1());
                }
            }
*/
            return _player.moves();
        } catch (Exception EXC) {
            System.out.println(EXC.getMessage());
            EXC.printStackTrace();
            throw new Exception("Player Error:  IFCPlayer.moves() Failure");
        }
    }

    public void gameOver() throws Exception {
        if (_player instanceof IFCPersistentPlayer) {
            ((IFCPersistentPlayer) _player).gameOver();
        }
    }

    public double score() throws Exception {
        return _score;
    }

    public void setScore(double __score) throws Exception {
        _score = __score;
    }

    public double totaltime() throws Exception {
        return _totaltime;
    }

    public void setTotalTime(double __totaltime) throws Exception {
        _totaltime = __totaltime;
    }

    public IFCPlayer player() {
        return _player;
    }
}
