HumanStrategy6.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics.Eventing.Reader;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using MauMau.Game.Interfaces;
  8. using MauMau.Logic;
  9. namespace MauMau.Game.Players
  10. {
  11. public class HumanStrategy6 : BasicPlayStrategy
  12. {
  13. public override GameAction GetNextAction(GameState state)
  14. {
  15. var standartAction = base.GetNextAction(state);
  16. if (standartAction != null)
  17. return standartAction;
  18. var returnAction = new GameAction();
  19. var playableCards =
  20. state.PlayerHands[_id].Where(m => m.CanPlayOnCard(state.TopCard, state.LastWishedColor)).ToList();
  21. if (state.PlayerHands[(_id + 1) % state.PlayerHands.Length].Count <= 2 && playableCards.FirstOrDefault(m => m.Number == Card.CardNumber.Sieben) != null)
  22. {
  23. returnAction.ActionType = GameAction.GameActionType.PlayCard;
  24. returnAction.PlayedCard = playableCards.FirstOrDefault(m => m.Number == Card.CardNumber.Sieben);
  25. return returnAction;
  26. }
  27. if (state.PlayerHands[(_id + 1) % state.PlayerHands.Length].Count <= 2 && playableCards.FirstOrDefault(m => m.Number == Card.CardNumber.Acht) != null)
  28. {
  29. returnAction.ActionType = GameAction.GameActionType.PlayCard;
  30. returnAction.PlayedCard = playableCards.FirstOrDefault(m => m.Number == Card.CardNumber.Acht);
  31. return returnAction;
  32. }
  33. // Does not work, fucks up the wished color altough no Bube is played
  34. //if (playableCards.Count <= 1 + playableCards.Count(m => m.Number == Card.CardNumber.Bube))
  35. //{
  36. // returnAction.ActionType = GameAction.GameActionType.PlayCard;
  37. // returnAction.PlayedCard = playableCards[0];
  38. // var cardsWithMostColor = state.PlayerHands[_id].OrderByDescending(m => m.Color).ToList();
  39. // returnAction.WishedColor = cardsWithMostColor[0].Color;
  40. // return returnAction;
  41. //}
  42. if (state.ParentState != null && state.ParentState.TopCard.CardRawValue == state.TopCard.CardRawValue)
  43. {
  44. var playableCardsWithLastColor = playableCards.Where(m => m.Color != state.TopCard.Color && m.Number != Card.CardNumber.Bube).ToList();
  45. if (playableCardsWithLastColor.Count > 0)
  46. {
  47. returnAction.ActionType = GameAction.GameActionType.PlayCard;
  48. returnAction.PlayedCard = playableCardsWithLastColor[Global.Random.Next(0, playableCardsWithLastColor.Count - 1)];
  49. return returnAction;
  50. }
  51. }
  52. var playableCardsWithoutBube = playableCards.Where(m => m.Number != Card.CardNumber.Bube).ToList();
  53. if (playableCardsWithoutBube.Count != 0)
  54. {
  55. var mostColorPlayableCardsWithoutBube = playableCardsWithoutBube.OrderBy(m => m.Color).ToList();
  56. var playableCardsMostColor =
  57. mostColorPlayableCardsWithoutBube.Where(m => m.Color == mostColorPlayableCardsWithoutBube[0].Color)
  58. .ToList();
  59. returnAction.ActionType = GameAction.GameActionType.PlayCard;
  60. returnAction.PlayedCard =
  61. playableCardsMostColor[Global.Random.Next(0, playableCardsMostColor.Count - 1)];
  62. }
  63. else
  64. {
  65. var cardsNotBube = state.PlayerHands[_id].Count(m => m.Number != Card.CardNumber.Bube);
  66. if (cardsNotBube == 0)
  67. {
  68. // Play random bube
  69. returnAction.ActionType = GameAction.GameActionType.PlayCard;
  70. returnAction.PlayedCard = playableCards[0];
  71. returnAction.WishedColor = Card.CardColor.Kreuz;
  72. return returnAction;
  73. }
  74. var mostHandColorWithoutBube =
  75. state.PlayerHands[_id].Where(m => m.Number != Card.CardNumber.Bube)
  76. .OrderBy(m => m.Color)
  77. .ToList()[0];
  78. returnAction.ActionType = GameAction.GameActionType.PlayCard;
  79. returnAction.PlayedCard =
  80. playableCards[0];
  81. returnAction.WishedColor = mostHandColorWithoutBube.Color;
  82. }
  83. return returnAction;
  84. }
  85. public void Init(int id)
  86. {
  87. this._id = id;
  88. }
  89. }
  90. }