## Remote Proxies

### Egoless programming and code review attitudes: 
- panelists' attitude 
- laughing 

### The Remote Proxy Pattern 

Blackjack/21 is a card game, with N players and 1 dealer:

    P1   P2   P3 ...
      \   |  /
          D

To play a game of blackjack, the dealer gives each player, and the dealer, two
cards. Each player, in turn, gets the decision to keep their current cards
("stay") or be dealt an additional card ("hit"). The process repeats until all
players are satisfied with their cards, or have exceeded 21. The winner(s) is
the player whose cards are closest to 21 without going over.

The rules of the game correspond to a pattern of interactions between the dealer
and a particular player.


	    dealer

	     |                            player
	     |    deal two cards            |
	     |----------------------------->|
	     |                              |
	     |  repeat until game over:     |
	     |                              |
	     |    request action            |
	     |----------------------------->|
	     |                              |
	     |           "stay" or "hit"    |
	     |<=============================|
	     |                              |
	     |  (optional) deal one card    |
	     |----------------------------->|
	     |                              |
	     |       ...                    |
	     |                              |
	     |    game is over              |
	     |----------------------------->|

We can directly translate this to an interface for Player components:

```
interface IPlayer:
  void DealHand(Card one, Card two)

  StayOrHit NextAction()

  void DealCard(Card one)

  void GameIsOver(Bool won?)
```

where `StayOrHit` is one of `"stay"` or `"hit"`, and a `Card` is a number from 1
to 52.

We can translate the protocol to be in terms of method call and returns:

	    dealer

	     |                            player
	     |    DealHand(one, two)        |
	     |----------------------------->|
	     |                              |
	     |  repeat until game over:     |
	     |                              |
	     |    NextAction()              |
	     |----------------------------->|
	     |           StayOrHit          |
	     |<=============================|
	     |    DealCard(one)             |
	     |----------------------------->|
	     |                              |
	     |       ...                    |
	     |                              |
	     |    GameIsOver(won?)          |
	     |----------------------------->|

From our experience so far, we should have no trouble implementing the dealer
and player in `$TEENAGE_HEARTBREAK_LANGUAGE` to run local games.

But, we want to allow players to run and connect from their own machines.

Because we've been following a design methodology and programming to interfaces,
we can employ the **REMOTE PROXY PATTERN** to gracefully scale from the
current "method" design to a remote one, instead of rewriting.

	           SERVER                            ||                CLIENT
	    dealer                  remote proxy     ||
	                            player           ||        relay
	     |                            |          ||           |               player
	     |    DealHand(one, two)      |         deal          | DealHand(..)    |
	     |--------------------------->|~~~~~~~~~~~~~~~~~~~~~~>|---------------->|
	     |                            |          ||           |                 |
	     |  repeat until game over:   |          ||           |                 |
	     |                            |          ||           |                 |
	     |    NextAction()            |         next          |  NextAction()   |
	     |--------------------------->|~~~~~~~~~~~~~~~~~~~~~~>|---------------->|
	     |                            |         stay-or-hit   |       StayOrHit |
	     |<===========================|<~~~~~~~~~~~~~~~~~~~~~~|<================|
	     |    DealCard(one)           |         hit           |  DealCard(..)   |
	     |--------------------------->|~~~~~~~~~~~~~~~~~~~~~~>|---------------->|
	     |                            |          ||           |                 |
	     |       ...                  |          ||           |                 |
	     |                            |          ||           |                 |
	     |    GameIsOver(won?)        |        game-over      |  GameIsOver(..) |
	     |--------------------------->|~~~~~~~~~~~~~~~~~~~~~~>|---------------->|

where the messages in the middle look like

| message     | format                   | interpretation
|-------------|--------------------------|-----------------
| deal        | ["deal", Card, Card]     | ...
| next        | "next"                   | ...
| stay-or-hit | ["action", STAY or HIT]  | ...
| hit         | ["hit", Card]            | ...
| game-over   | ["game over", Bool]      | ...

A proxy is an object that stands in for another object, forwarding incoming
messages, sometimes altering the behavior in a certain way.

In this case, we want to create a proxy for a remote object, i.e. a Player
object on another machine.

That means "forwarding incoming messages" will mean network communication.

On the server, we replace the Player with the proxy, but our Player object on
the client doesn't understand network messages. So we will also create a
Relay on the client that receives the incoming network messages and translates them to
method calls, sending back the results.

Concretely, the relay looks like:

```
class Relay:
  Relay(Player p, Connection conn) {
    conn.connect()
    while (True):
      match conn.receive()
        ["deal", c1, c2]   => p.DealHand(c1, c2)
        "next"             => let answer = p.NextAction() in conn.send(answer)
        ["hit", c1]        => p.DealCard(c1)
        ["game over", won] => p.GameIsOver(won); break
  }
```

### Review 1

| Matthias 	         | Jason  		  | Role		   |
| ---------------------- | ---------------------- | ---------------------- |
| Nicholas Ippoliti | Jameson O'Connor | presenter |
| Darren Roscoe | Jack Davis |           |
|                   |                   | panelists |
| Agustin Romero | Nate Geyer | head |
| Oliver Zheng | Will Angell-James | assistant |
| David Reed | Ian Meyers | secretary |


### Review 2 

| Matthias 	         | Jason  		  | Role		   |
| ---------------------- | ---------------------- | ---------------------- |
| Jason Fiammetta | Aaron Levine | presenter |
| Peter Dirksmeier | Daniel Gimeno |           |
|                   |                   | panelists |
| Laura Romero-Suarez | Zachary Reiter | head |
| Patrick Watrous | Kevin Liang | assistant |
| Oliver Spohngellert | Nate Geyer | secretary |
