#!/usr/bin/python

import random
from guild.actor import *


class InsufficientFunds(ActorException):
    pass


class Account(Actor):
    def __init__(self, balance=10):
        super(Account, self).__init__()
        self.balance = balance

    @actor_function
    def deposit(self, amount):
        # This is a function to allow the deposit to be confirmed
        print "DEPOSIT", "\t", amount, "\t", self.balance
        self.balance = self.balance + amount
        return self.balance

    @actor_function
    def withdraw(self, amount):
        if self.balance < amount:
            raise InsufficientFunds("Insufficient Funds in your account",
                                    requested=amount,
                                    balance=self.balance)
        self.balance = self.balance - amount
        print "WITHDRAW", "\t", amount, "\t", self.balance
        return amount


def transfer(amount, payer, payee):
    funds = payer.withdraw(amount)
    payee.deposit(funds)


class MischiefMaker(Actor):
    def __init__(self, myaccount, friendsaccount):
        super(MischiefMaker, self).__init__()
        self.myaccount = myaccount
        self.friendsaccount = friendsaccount
        self.grabbed = 0

    @process_method
    def process(self):
        try:
            grab = random.randint(1, 10) * 10
            transfer(grab, self.friendsaccount, self.myaccount)
        except InsufficientFunds as e:
            print "Awww, Tapped out", e.balance, "<", e.requested
            self.stop()
            return
        self.grabbed = self.grabbed + grab


account1 = Account(1000).go()
account2 = Account(1000).go()

fred = MischiefMaker(account1, account2).go()
barney = MischiefMaker(account2, account1).go()


wait_for(fred, barney)

account1.stop()
account2.stop()
account1.join()
account2.join()

print "GAME OVER"

print "Fred grabbed", fred.grabbed
print "Barney grabbed", barney.grabbed
print "Total grabbed", fred.grabbed + barney.grabbed
print "Since they stopped grabbing..."
print "Money left", account1.balance, account2.balance
print "Ending money", account1.balance + account2.balance

@@ -366,17 +366,17 @@
    print
- 
+(
 %22DEPOSIT
@@ -402,32 +402,33 @@
 t%22, self.balance
+)
 %0A        self.ba
@@ -816,17 +816,17 @@
    print
- 
+(
 %22WITHDRA
@@ -861,16 +861,17 @@
 .balance
+)
 %0A       
@@ -1442,79 +1442,295 @@
 rint
- %22Awww, Tapped out%22, e.balance, %22%3C%22, e.requested%0A            self.stop(
+(%22----------------------------------------------------------------%22)%0A            print(%22Awww, Tapped out%22, e.balance, %22%3C%22, e.requested, %22::%22, (self.__class__.__name__, id(self)))%0A            self.stop()%0A            print(%22----------------------------------------------------------------%22
 )%0A  
@@ -2042,17 +2042,17 @@
 )%0A%0Aprint
- 
+(
 %22GAME OV
@@ -2058,16 +2058,17 @@
 VER%22
+)
 %0A%0Aprint
- 
+(
 %22Fre
@@ -2091,23 +2091,24 @@
 .grabbed
+)
 %0Aprint
- 
+(
 %22Barney 
@@ -2131,23 +2131,24 @@
 .grabbed
+)
 %0Aprint
- 
+(
 %22Total g
@@ -2185,23 +2185,24 @@
 .grabbed
+)
 %0Aprint
- 
+(
 %22Since t
@@ -2225,23 +2225,24 @@
 bing...%22
+)
 %0Aprint
- 
+(
 %22Money l
@@ -2285,15 +2285,16 @@
 ance
+)
 %0Aprint
- 
+(
 %22End
@@ -2332,17 +2332,18 @@
 account2.balance
+)
 %0A

Update example to python 3