Rock-paper-scissors: Difference between revisions

Content added Content deleted
m (→‎traditional, 3 choices: added/changed wording in the REXX section header.)
(add supercollider)
Line 4,659: Line 4,659:
4:1 Play: q
4:1 Play: q
</pre>
</pre>


=={{header|SuperCollider}}==

<pre>
// play it in the REPL:

a = RockPaperScissors.new;
a.next(Scissors);
a.next(Scissors);
a.next(Scissors);
a.next(Paper);
</pre>

An implementation using classes

<pre>
Rock {

*play { |other|
^other.rock + this + "against" + other
}

*rock {
^"tie"
}

*paper {
^"lose"
}

*scissors {
^"win"
}

*losesAgainst {
^Paper
}


}

Paper {

*play { |other|
^other.paper + this + "against" + other
}

*paper {
^"tie"
}

*scissors {
^"lose"
}

*rock {
^"win"
}

*losesAgainst {
^Scissors
}

}

Scissors {

*play { |other|
^other.scissors + this + "against" + other
}

*scissors {
^"tie"
}

*rock {
^"lose"
}

*paper {
^"win"
}

*losesAgainst {
^Rock
}

}

RockPaperScissors {
var opponentMoves;

*new {
^super.new.init
}

init {
opponentMoves = Bag.new;
}

findBestMatch {
var typicalMove = opponentMoves.wchoose;
if(typicalMove.isNil) { ^[Rock, Paper, Scissors].choose };
^typicalMove.losesAgainst
}

next { |otherMove|
var myMove = this.findBestMatch;
opponentMoves.add(otherMove);
^play(otherMove, myMove)
}

}





</pre>



=={{header|Tcl}}==
=={{header|Tcl}}==