Java poker implementation
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

RandomPlayer.java 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. * Copyright (c) Chris 'MD87' Smith, 2007. All rights reserved.
  3. *
  4. * This code may not be redistributed without prior permission from the
  5. * aforementioned copyright holder(s).
  6. */
  7. package com.md87.cardgame.controllers;
  8. import com.md87.cardgame.Deck;
  9. import com.md87.cardgame.Player;
  10. import com.md87.cardgame.Player.CallRaiseFold;
  11. import com.md87.cardgame.Player.OpenCheck;
  12. import com.md87.cardgame.interfaces.Game;
  13. import com.md87.cardgame.interfaces.PlayerController;
  14. /**
  15. *
  16. * @author Chris
  17. */
  18. public class RandomPlayer implements PlayerController {
  19. protected Player player;
  20. protected Game game;
  21. public CallRaiseFold doCallRaiseFold(int callAmount, boolean canRaise) {
  22. if (Math.random() < 0.3) {
  23. if (player.getCash() - callAmount < game.getBigBlind() || !canRaise) {
  24. return CallRaiseFold.FOLD;
  25. } else {
  26. return CallRaiseFold.RAISE;
  27. }
  28. } else {
  29. return CallRaiseFold.CALL;
  30. }
  31. }
  32. public OpenCheck doOpenCheck() {
  33. if (Math.random() < 0.5 || player.getCash() < game.getBigBlind()) {
  34. return OpenCheck.CHECK;
  35. } else {
  36. return OpenCheck.OPEN;
  37. }
  38. }
  39. public boolean shouldShowCards() {
  40. return false;
  41. }
  42. public void setPlayer(Player player) {
  43. this.player = player;
  44. }
  45. public void setGame(Game game) {
  46. this.game = game;
  47. }
  48. public int getRaise(int minimum) {
  49. return minimum;
  50. }
  51. /** {@inheritDoc} */
  52. public boolean isLocalHuman() {
  53. return false;
  54. }
  55. /** {@inheritDoc} */
  56. public Deck discardCards(final int minimum, final int maximum) {
  57. return new Deck(player.getCards().subList(0, minimum));
  58. }
  59. }