--------------080203000606040706000600
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit

Ruby Quiz wrote:

> Your task is to build a strategy for playing the game of Paper Rock Scissors
> against all manner of opponents.  The question here is if you can adapt to an
> opponent's strategy and seize the advantage, while he is doing the same to you
> of course.

My implementation might be considered cheating (it tries to get a test
copy of its enemy so it can find out what it is going to do and respond
to that), but it's an interesting one anyway.

I've also attached a few just for fun mirror players which will base
their behavior on that of their opponents strategy.

The attached rand player is one of the simplest strategies you can use,
but one that is pretty much guaranteed to give you a 50% chance of
winning. (Unless your enemy is able to simulate Ruby's RNG and thus is
able to guess what you will do.)


--------------080203000606040706000600
Content-Type: application/x-ruby;
 nameg_spy_player.rb"
Content-Transfer-Encoding: base64
Content-Disposition: inline;
 filenameg_spy_player.rb"

IyBUcmllcyB0byBmb29sIHRoZSBvdGhlciBwbGF5ZXIgaW50byB0aGlua2luZyBpdCBpcyBh
IEpFR1BhcGVyUGxheWVyLg0KIyBXaWxsIHJlc3BvbmQgd2l0aCBhbiBvcHRpbWFsIGNob2lj
ZSB0byB0aGUgZW5lbXkncyBjaG9pY2UgaW4gb3JkZXIgdG8gd2luLg0KIyBJZiBpdCBkZXRl
Y3RzIGl0cyBvd24gdGFjdGljIGJlaW5nIHVzZWQgYWdhaW5zdCBpdCwgaXQgd2lsbCByZXNw
b25kIGp1c3QNCiMgbGlrZSB0aGUgSkVHUGFwZXJQbGF5ZXIgd291bGQgaGF2ZSBieSBhbHdh
eXMgcGlja2luZyA6cGFwZXIuDQojIENoYW5jZXMgb2Ygd2lubmluZyBjb3VsZCBiZSBpbXBy
b3ZlZCBieSBkZXRlY3RpbmcgdGhlIGNob2ljZXMgZG9uZSBieQ0KIyBwbGF5ZXJzIHVzaW5n
IHJhbmQoKSwgYnV0IHRoYXQgd291bGQgcmVxdWlyZSBhIHdheSBvZiBkZXRlY3RpbmcgdGhl
DQojIHN0YXRlIG9mIFJ1YnkncyByYW5kb20gbnVtYmVyIGdlbmV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vPywgOnBsYXldDQogICAgICByYW5kX2Nob2lj
ZQ0KICAgIGVsc2UNCiAgICAgIHRlc3Rfb3Bwb25lbnQgPSBiZWdpbg0KICAgICAgICBNYXJz
aGFsLmxvYWQoTWFyc2hhbC5kdW1wKEBvcHBvbmVudCkpDQogICAgICByZXNjdWUgRXhjZXB0
aW9uDQogICAgICAgIG9ial9jYWxsW0BvcHBvbmVudCwgOmNsb25lXQ0KICAgICAgZW5kDQoN
CiAgICAgIG90aGVyX2Nob2ljZSA9IHBsYXkodGVzdF9vcHBvbmVudCkNCg0KICAgICAgY2Fz
ZSBvdGhlcl9jaG9pY2UNCiAgICAgICAgd2hlbiA6cGFwZXIgdGhlbiA6c2Npc3NvcnMNCiAg
ICAgICAgd2hlbiA6cm9jayB0aGVuIDpwYXBlcg0KICAgICAgICB3aGVuIDpzY2lzc29ycyB0
aGVuIDpyb2NrDQogICAgICAgIGVsc2UgcmFuZF9jaG9pY2UNCiAgICAgIGVuZA0KICAgIGVu
ZA0KICByZXNjdWUgRXhjZXB0aW9uDQogICAgcmFuZF9jaG9pY2UNCiAgZW5kDQoNCiAgIyBG
b29scyBzaW1wbGUgY2FsbGVyIGNoZWNrcw0KICBkZWYgcGxheShvcHBvbmVudCkNCiAgICBv
cHBvbmVudC5jaG9vc2UNCiAgZW5kDQoNCiAgZGVmIHJhbmRfY2hvaWNlKCkNCiAgICBbOnBh
cGVyLCA6cm9jaywgOnNjaXNzb3JzXS5zb3J0X2J5IHsgS2VybmVsLnJhbmQgfS5maXJzdA0K
ICBlbmQNCmVuZA0K
--------------080203000606040706000600
Content-Type: application/x-ruby;
 nameg_mirror.rb"
Content-Transfer-Encoding: base64
Content-Disposition: inline;
 filenameg_mirror.rb"

Y2xhc3MgRkdNaXJyb3IgPCBQbGF5ZXINCiAgZGVmIGluaXRpYWxpemUob3RoZXIpDQogICAg
QHBsYXllciA9IGlmIG90aGVyWyJNaXJyb3IiXSB0aGVuDQogICAgICBDbGFzcy5uZXcgZG8N
CiAgICAgICAgZGVmIGNob29zZSgpIG5pbCBlbmQNCiAgICAgIGVuZC5uZXcNCiAgICBlbHNl
DQogICAgICBPYmplY3QuY29uc3RfZ2V0KG90aGVyKS5uZXcob3RoZXIpDQogICAgZW5kDQog
IGVuZA0KDQogIGRlZiBjaG9vc2UoKQ0KICAgIGlmIGNhbGxlclswXVsiaW4gYHBsYXknIl0g
dGhlbg0KICAgICAgcGxheQ0KICAgIGVsc2UNCiAgICAgIEBwbGF5ZXIuY2hvb3NlDQogICAg
ZW5kIHx8IHJhbmRfY2hvaWNlDQogIGVuZA0KDQogIGRlZiByYW5kX2Nob2ljZSgpDQogICAg
WzpwYXBlciwgOnJvY2ssIDpzY2lzc29yc10uc29ydF9ieSB7IEtlcm5lbC5yYW5kIH0uZmly
c3QNCiAgZW5kDQoNCiAgZGVmIHBsYXkoKQ0KICAgIEBwbGF5ZXIuY2hvb3NlDQogIGVuZA0K
DQogIGRlZiBtZXRob2RfbWlzc2luZyhuYW1lLCAqYXJncykNCiAgICBAcGxheWVyLnNlbmQo
bmFtZSwgKmFyZ3MpDQogIHJlc2N1ZSBFeGNlcHRpb24gPT4gZXJyDQogICAgcHV0cyBlcnIs
IGVyci5iYWNrdHJhY2UNCiAgZW5kDQplbmQNCg--------------080203000606040706000600
Content-Type: application/x-ruby;
 nameg_anti_mirror.rb"
Content-Transfer-Encoding: base64
Content-Disposition: inline;
 filenameg_anti_mirror.rb"

Y2xhc3MgRkdBbnRpTWlycm9yIDwgUGxheWVyDQogIGRlZiBpbml0aWFsaXplKG90aGVyKQ0K
ICAgIEBwbGF5ZXIgPSBpZiBvdGhlclsiTWlycm9yIl0gdGhlbg0KICAgICAgQ2xhc3MubmV3
IGRvDQogICAgICAgIGRlZiBjaG9vc2UoKSBuaWwgZW5kDQogICAgICBlbmQubmV3DQogICAg
ZWxzZQ0KICAgICAgT2JqZWN0LmNvbnN0X2dldChvdGhlcikubmV3KG90aGVyKQ0KICAgIGVu
ZA0KICBlbmQNCg0KICBkZWYgY2hvb3NlKCkNCiAgICBjaG9pY2UgPSBpZiBjYWxsZXJbMF1b
ImluIGBwbGF5JyJdIHRoZW4NCiAgICAgIHBsYXkNCiAgICBlbHNlDQogICAgICBAcGxheWVy
LmNob29zZQ0KICAgIGVuZCB8fCByYW5kX2Nob2ljZQ0KDQogICAgY2hvaWNlcyA9IFs6cGFw
ZXIsIDpyb2NrLCA6c2Npc3NvcnNdIC0gW2Nob2ljZV0NCiAgICBjaG9pY2VzLnNvcnRfYnkg
eyBLZXJuZWwucmFuZCB9LmZpcnN0DQogIGVuZA0KDQogIGRlZiByYW5kX2Nob2ljZSgpDQog
ICAgWzpwYXBlciwgOnJvY2ssIDpzY2lzc29yc10uc29ydF9ieSB7IEtlcm5lbC5yYW5kIH0u
Zmlyc3QNCiAgZW5kDQoNCiAgZGVmIHBsYXkoKQ0KICAgIEBwbGF5ZXIuY2hvb3NlDQogIGVu
ZA0KDQogIGRlZiBtZXRob2RfbWlzc2luZyhuYW1lLCAqYXJncykNCiAgICBAcGxheWVyLnNl
bmQobmFtZSwgKmFyZ3MpDQogIHJlc2N1ZSBFeGNlcHRpb24gPT4gZXJyDQogICAgcHV0cyBl
cnIsIGVyci5iYWNrdHJhY2UNCiAgZW5kDQplbmQNCg--------------080203000606040706000600
Content-Type: application/x-ruby;
 nameg_attack_mirror.rb"
Content-Transfer-Encoding: base64
Content-Disposition: inline;
 filenameg_attack_mirror.rb"

Y2xhc3MgRkdBdHRhY2tNaXJyb3IgPCBQbGF5ZXINCiAgZGVmIGluaXRpYWxpemUob3RoZXIp
DQogICAgQHBsYXllciA9IGlmIG90aGVyWyJNaXJyb3IiXSB0aGVuDQogICAgICBDbGFzcy5u
ZXcgZG8NCiAgICAgICAgZGVmIGNob29zZSgpIGVuZA0KICAgICAgICBkZWYgcmVzdWx0KHlv
dSwgdGhlbSwgd2luX2xvc2Vfb3JfZHJhdykgZW5kDQogICAgICBlbmQubmV3DQogICAgZWxz
ZQ0KICAgICAgT2JqZWN0LmNvbnN0X2dldChvdGhlcikubmV3KG90aGVyKQ0KICAgIGVuZA0K
ICBlbmQNCg0KICBkZWYgY2hvb3NlKCkNCiAgICBjaG9pY2UgPSBpZiBjYWxsZXJbMF1bImlu
IGBwbGF5JyJdIHRoZW4NCiAgICAgIHBsYXkNCiAgICBlbHNlDQogICAgICBAcGxheWVyLmNo
b29zZQ0KICAgIGVuZCB8fCByYW5kX2Nob2ljZQ0KDQogICAgYXR0YWNrKGNob2ljZSkNCiAg
ZW5kDQoNCiAgZGVmIGF0dGFjayhjaG9pY2UpDQogICAgY2FzZSBjaG9pY2UNCiAgICAgIHdo
ZW4gOnBhcGVyIHRoZW4gOnNjaXNzb3JzDQogICAgICB3aGVuIDpyb2NrIHRoZW4gOnBhcGVy
DQogICAgICB3aGVuIDpzY2lzc29ycyB0aGVuIDpyb2NrDQogICAgZW5kDQogIGVuZA0KDQog
IGRlZiByYW5kX2Nob2ljZSgpDQogICAgWzpwYXBlciwgOnJvY2ssIDpzY2lzc29yc10uc29y
dF9ieSB7IEtlcm5lbC5yYW5kIH0uZmlyc3QNCiAgZW5kDQoNCiAgZGVmIHBsYXkoKQ0KICAg
IEBwbGF5ZXIuY2hvb3NlDQogIGVuZA0KDQogIGRlZiByZXN1bHQoeW91LCB0aGVtLCB3aW5f
bG9zZV9vcl9kcmF3KQ0KICAgIEBwbGF5ZXIucmVzdWx0KGF0dGFjayh5b3UpLCB0aGVtLCB3
aW5fbG9zZV9vcl9kcmF3KQ0KICBlbmQNCg0KICBkZWYgbWV0aG9kX21pc3NpbmcobmFtZSwg
KmFyZ3MpDQogICAgQHBsYXllci5zZW5kKG5hbWUsICphcmdzKQ0KICByZXNjdWUgRXhjZXB0
aW9uID0+IGVycg0KICAgIHB1dHMgZXJyLCBlcnIuYmFja3RyYWNlDQogIGVuZA0KZW5kDQo--------------080203000606040706000600
Content-Type: application/x-ruby;
 nameg_rand_player.rb"
Content-Transfer-Encoding: base64
Content-Disposition: inline;
 filenameg_rand_player.rb"

Y2xhc3MgRkdSYW5kUGxheWVyIDwgUGxheWVyDQogIGRlZiBjaG9vc2UNCiAgICBbOnBhcGVy
LCA6cm9jaywgOnNjaXNzb3JzXVtyYW5kKDMpXQ0KICBlbmQNCmVuZA0K
--------------080203000606040706000600--