@@ -69,10 +69,17 @@ public override void EndTurn(PlayerTurnContext context)
69
69
// TODO: Improve close game decision
70
70
private bool CloseGame ( PlayerTurnContext context )
71
71
{
72
- var shouldCloseGame = this . PlayerActionValidator . IsValid ( PlayerAction . CloseGame ( ) , context , this . Cards )
73
- && this . Cards . Count ( x => x . Suit == context . TrumpCard . Suit ) == 5 ;
72
+ if ( ! this . PlayerActionValidator . IsValid ( PlayerAction . CloseGame ( ) , context , this . Cards ) )
73
+ {
74
+ return false ;
75
+ }
76
+
77
+ if ( this . Cards . Count ( x => x . Suit == context . TrumpCard . Suit ) == 5 )
78
+ {
79
+ return true ;
80
+ }
74
81
75
- return shouldCloseGame ;
82
+ return false ;
76
83
}
77
84
78
85
// TODO: Improve choosing best card to play
@@ -103,7 +110,7 @@ private PlayerAction ChooseCardWhenPlayingFirstAndRulesDoNotApply(
103
110
}
104
111
105
112
// If the player is close to the win => play trump card which will surely win the trick
106
- var cardToWinTheGame = this . GetTrumpCardWhichWillSurelyWinTheGame ( context . TrumpCard , context . FirstPlayerRoundPoints , possibleCardsToPlay ) ;
113
+ var cardToWinTheGame = this . GetTrumpCardWhichWillSurelyWinTheGame ( context . TrumpCard . Suit , context . FirstPlayerRoundPoints , possibleCardsToPlay ) ;
107
114
if ( cardToWinTheGame != null )
108
115
{
109
116
return this . PlayCard ( cardToWinTheGame ) ;
@@ -134,7 +141,6 @@ private PlayerAction ChooseCardWhenPlayingFirstAndRulesApply(
134
141
135
142
var trumpCard = this . GetCardWhichWillSurelyWinTheTrick (
136
143
context . TrumpCard . Suit ,
137
- context . CardsLeftInDeck == 0 ? null : context . TrumpCard ,
138
144
opponentHasTrump ) ;
139
145
if ( trumpCard != null )
140
146
{
@@ -145,7 +151,6 @@ private PlayerAction ChooseCardWhenPlayingFirstAndRulesApply(
145
151
{
146
152
var possibleCard = this . GetCardWhichWillSurelyWinTheTrick (
147
153
suit ,
148
- context . CardsLeftInDeck == 0 ? null : context . TrumpCard ,
149
154
opponentHasTrump ) ;
150
155
if ( possibleCard != null )
151
156
{
@@ -270,16 +275,16 @@ private PlayerAction ChooseCardWhenPlayingSecondAndRulesApply(
270
275
}
271
276
272
277
private Card GetTrumpCardWhichWillSurelyWinTheGame (
273
- Card trumpCard ,
278
+ CardSuit trumpSuit ,
274
279
int playerRoundPoints ,
275
280
ICollection < Card > possibleCardsToPlay )
276
281
{
277
282
var opponentBiggestTrumpCard =
278
- this . cardTracker . UnknownCards . Where ( x => x . Suit == trumpCard . Suit )
283
+ this . cardTracker . UnknownCards . Where ( x => x . Suit == trumpSuit )
279
284
. OrderByDescending ( x => x . GetValue ( ) )
280
285
. FirstOrDefault ( ) ;
281
286
var myBiggestTrumpCards =
282
- possibleCardsToPlay . Where ( x => x . Suit == trumpCard . Suit ) . OrderByDescending ( x => x . GetValue ( ) ) ;
287
+ possibleCardsToPlay . Where ( x => x . Suit == trumpSuit ) . OrderByDescending ( x => x . GetValue ( ) ) ;
283
288
284
289
var sumOfPoints = 0 ;
285
290
foreach ( var myTrumpCard in myBiggestTrumpCards )
@@ -298,7 +303,7 @@ private Card GetTrumpCardWhichWillSurelyWinTheGame(
298
303
return null ;
299
304
}
300
305
301
- private Card GetCardWhichWillSurelyWinTheTrick ( CardSuit suit , Card trumpCard , bool opponentHasTrump )
306
+ private Card GetCardWhichWillSurelyWinTheTrick ( CardSuit suit , bool opponentHasTrump )
302
307
{
303
308
var myBiggestCard =
304
309
this . Cards . Where ( x => x . Suit == suit ) . OrderByDescending ( x => x . GetValue ( ) ) . FirstOrDefault ( ) ;
0 commit comments