contract BlockPaperScissors is Ownable {

  using SafeMath for uint256;

    ERC20Interface bCoin;
    ERC20Interface pCoin;
    ERC20Interface sCoin;
    ERC20Interface tCoin;

    address public rpsDev = msg.sender;
    uint8 public lastMove = 1; // last played move; 1=rock, 2=paper, 3=scissor
    address public lastPlayer = msg.sender;
    uint public oneCoin = 1000000000000000000;

//FUNCTIONS setting and retrieving global variables that impact gameplay

    function setBCoinContractAddress(address _address) external onlyOwner {
      bCoin = ERC20Interface(_address);
    }
    function setPCoinContractAddress(address _address) external onlyOwner {
      pCoin = ERC20Interface(_address);
    }
    function setSCoinContractAddress(address _address) external onlyOwner {
      sCoin = ERC20Interface(_address);
    }
    function setTCoinContractAddress(address _address) external onlyOwner {
      tCoin = ERC20Interface(_address);
    }

//EVENTS

    event newMove(uint8 move);
    event newWinner(address winner);

// FUNCTIONS interacting with the swine structs in contract

    function playBps(uint8 _choice) public returns (uint8) {
      require (_choice == 1 || _choice == 2 || _choice == 3);
      if (_choice == lastMove) {
        tCoin.transfer(msg.sender, oneCoin);
        tCoin.transfer(lastPlayer, oneCoin);// send tie token to each player
        setGame(_choice, msg.sender);
        return 3; // it's a tie
      }
      if (_choice == 1) { //choice is block
        if (lastMove == 3) {
          bCoin.transfer(msg.sender, oneCoin);
          emit newWinner(msg.sender);
          setGame(_choice, msg.sender);
          return 1;// win
          } else {
          pCoin.transfer(lastPlayer, oneCoin);
          emit newWinner(lastPlayer);
          setGame(_choice, msg.sender);
          return 2;//lose
          }
      }
      if (_choice == 2) { // choice is paper
        if (lastMove == 1) {
          pCoin.transfer(msg.sender, oneCoin);
          emit newWinner(msg.sender);
          setGame(_choice, msg.sender);
          return 1;// win
          } else {
          sCoin.transfer(lastPlayer, oneCoin);
          emit newWinner(lastPlayer);
          setGame(_choice, msg.sender);
          return 2;//lose
          }
      }
      if (_choice == 3) { // choice is scissors
        if (lastMove == 2) {
          sCoin.transfer(msg.sender, oneCoin);
          emit newWinner(msg.sender);
          setGame(_choice, msg.sender);
          return 1;// win
          } else {
          bCoin.transfer(lastPlayer, oneCoin);
          emit newWinner(lastPlayer);
          setGame(_choice, msg.sender);
          return 2;//lose
          }
      }
    }

    function setGame(uint8 _move, address _player) private {
      lastMove = _move;
      lastPlayer = _player;
      emit newMove(_move);
    }

}
function setBCoinContractAddress(address _address) external onlyOwner {
      bCoin = ERC20Interface(_address);
    }
//FUNCTIONS setting and retrieving global variables that impact gameplay