package com.egloos.realmove.dp.strategy; import com.egloos.realmove.dp.strategy.framework.Hand; import com.egloos.realmove.dp.strategy.framework.HandGameStrategy; /** * ´ÙÀ½ ³»¹Ð ¼ÕÀ» Random ÇÏ°Ô °áÁ¤ÇÏÁö¸¸, °ú°ÅÀÇ ½Â·üÀ» ¹Ý¿µÇÏ¿© ³­¼ö¸¦ °è»êÇÑ´Ù.
* ¿¹ÄÁ´ë, ÁÖ¸ÔÀÌ À̱ä Ƚ¼ö°¡ ¸¹´Ù¸é ´ÙÀ½¿¡µµ ÁÖ¸ÔÀ» ³¾ È®·üÀÌ Á»´õ ³ô´Ù. * */ public class ProbStrategy implements HandGameStrategy { private Hand prevHand = null; private int[] winCount = new int[3]; public ProbStrategy() { winCount[0] = 1; winCount[1] = 1; winCount[2] = 1; } public Hand getRandom() { int i = (int) ( Math.random() * ( winCount[0] + winCount[1] + winCount[2] ) ); if ( i < winCount[0] ) { return Hand.SCISSOR; } else if ( i < winCount[0] + winCount[1] ) { return Hand.ROCK; } else { return Hand.PAPER; } } @Override public Hand next() { this.prevHand = getRandom(); return this.prevHand; } @Override public void study( int result ) { winCount[ this.prevHand.getValue() ]++; } }