package exercises.Dice; import java.util.Random; /** * * @author Lefteris Moussiades */ class FairDicePlayer { Random r; public FairDicePlayer() { r=new Random(); } int play() { return r.nextInt(6)+1; } } class Two605DicePlayer { Random r; public Two605DicePlayer() { r=new Random(); } int play() { int rVal=r.nextInt(6)+1; if (rVal==5) return 6; return rVal; } } class Stats { FairDicePlayer fp; Two605DicePlayer two6; int fpScore; int two6Score; } public class DiceGame { Stats stats; public DiceGame() { stats=new Stats(); stats.fp=new FairDicePlayer(); stats.two6=new Two605DicePlayer(); } public void oneDiceGame() { for (int i=0; i<10; i++) { int fpZaria=stats.fp.play(); int two6Zaria=stats.two6.play(); if (fpZaria==two6Zaria) continue; if (fpZaria>two6Zaria) stats.fpScore+=fpZaria; else stats.two6Score+=two6Zaria; } } public void play() { for (int i=0; i<100; i++) { oneDiceGame(); } System.out.println("FairPlayer score "+stats.fpScore); System.out.println("two605Player score "+stats.two6Score); } public static void main(String[] args) { DiceGame dG=new DiceGame(); dG.play(); } }