🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.language
Article #18214

Interesting Java Question

#18214
From: javahelp
Date: Wed, 29 Jul 1998 00:00
38 lines
2588 bytes
Hi I'm new to Jbuilder..I got the following question from a book but
have no idea how to solve this kind of problem.....
--------------------------------------------------------------------------------------------------------------------------

You must first define a java interface Player representing the
communications protocol between the main program and a player object.
You must then define three classes, each implementing the Player
interface with a different strategy for playing the game.  The choice of
startegy is left to you but at least one of these strategies must
consider the opponent's previous choicce when making a decision.

Your main program should create an array referencing at least one object
of each of the three player classes and then play each player object
against each other object 100 times.  Note that an object does not play
itself.  Finally the main program should print out to the console window
the class name of each player along with its final score.

The protocol for playing a single encounter between two players is as
follows:  For each pair of players (referring to them as Player i and
Player j) the main program must perform the following steps:

1.  Send Player i the message play(j) where j is an integer (the array
index of the opponent).  This informs it that it is playing against
Player j.  The return value of this method call is Player i's choice
represented as a char (c=cooperate, d=defect)

2.  Send Player j the message play(i).  Player j returns its choice.

3.  Send Player i the message opponentsChoice(j,cj) where cj is the
choice Player j just made.  This allows Player i to remember what Player
j played.  Note that a class need not do anything when this message is
received unless it wishes to record this information for future use.

4.  Send Player j the message opponentsChoice(i,ci) where ci is the
choice Player i just made

5.  Calculate and record each player's score
---------------------------------------------------------------------------------------------------------------
Technical Details
Message-ID: <35BEF1F4.599DE2F1@iname.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f74b3,9113e0d024fe963b,start
X-Google-Attributes: gidf74b3,public
From: javahelp@iname.com
Subject: Interesting Java Question
Date: 1998/07/29
Message-ID: <35BEF1F4.599DE2F1@iname.com>
X-Deja-AN: 375944439
Content-Transfer-Encoding: 7bit
X-Accept-Language: en
Content-Type: text/plain; charset=us-ascii
Organization: Another Netscape Collabra Server User
Mime-Version: 1.0
Newsgroups: borland.public.jbuilder.java.language