Texas Hold-em challenge

Over the past couple of days I’ve been doing some code training with a CodeWars: Texas Hold-Em kata

Be prepared though to spend all day on this kata, and a second day to debug niggling remaining issues with it too.
CodeWars found some interesting problems in my initial attempt by throwing random cards at the problem, such as when three pairs turned up with a low third pair.

If anyone’s interested in doing the Texas Hold’em kata, these are the tests:

describe('Execute Example Tests', function(){
	it('Let\'s play!', function(){
		assertEquals({type:'nothing', ranks:['A','K','Q','J','9']},hand(['K♠','A♦'],['J♣','Q♥','9♥','2♥','3♦']));
		assertEquals({type:'pair', ranks:['Q','K','J','9']},hand(['K♠','Q♦'],['J♣','Q♥','9♥','2♥','3♦']));
		assertEquals({type:'two pair', ranks:['K','J','9']},hand(['K♠','J♦'],['J♣','K♥','9♥','2♥','3♦']));
		assertEquals({type:'three-of-a-kind', ranks:['Q','J','9']},hand(['4♠','9♦'],['J♣','Q♥','Q♠','2♥','Q♦']));
		assertEquals({type:'straight', ranks:['K','Q','J','10','9']},hand(['Q♠','2♦'],['J♣','10♥','9♥','K♥','3♦']));
		assertEquals({type:'flush', ranks:['Q','J','10','5','3']},hand(['A♠','K♦'],['J♥','5♥','10♥','Q♥','3♥']));
		assertEquals({type:'full house', ranks:['A','K']},hand(['A♠','A♦'],['K♣','K♥','A♥','Q♥','3♦']));
		assertEquals({type:'four-of-a-kind', ranks:['2','3']},hand(['2♠','3♦'],['2♣','2♥','3♠','3♥','2♦']));
		assertEquals({type:'straight-flush', ranks:['J','10','9','8','7']},hand(['8♠','6♠'],['7♠','5♠','9♠','J♠','10♠']));
	});
});

And when you think that your code is ready and passing, these are the additional tests that broke my initial code:

assertEquals({"type":"straight-flush","ranks":["J","10","9","8","7"]},hand(['7♠','2♦'],['10♠','8♠','K♦','9♠','J♠']));
assertEquals({"type":"straight-flush","ranks":["J","10","9","8","7"]},hand(['8♠','J♦'],['8♣','8♦','10♦','9♦','7♦']));
assertEquals({"type":"straight-flush","ranks":["9","8","7","6","5"]},hand(['7♥','8♥'],['9♥','6♥','10♣','5♥','J♥']));
assertEquals({"type":"straight","ranks":["7","6","5","4","3"]},hand(['2♥','7♣'],['3♥','5♠','5♦','4♣','6♦']));
assertEquals({"type":"straight","ranks":["10","9","8","7","6"]},hand(['7♠','6♦'],['10♠','9♠','10♥','9♥','8♦']));
assertEquals({"type":"straight-flush","ranks":["A","K","Q","J","10"]},hand(['A♦','K♥'],['Q♦','J♦','10♦','2♦','K♦']));
assertEquals({"type":"straight-flush","ranks":["7","6","5","4","3"]},hand(['6♠','K♠'],['4♣','7♣','6♣','5♣','3♣']));
assertEquals({"type":"two pair","ranks":["7","4","K"]},hand(['7♦','K♥'],['7♠','3♣','4♥','3♥','4♦']));

All in all this kata was well worth the challenge and had me realising that I need to refactor my code much more frequently than I currently do.

It ended up being a more complex challenge that I initially thought it would be. However, there are even more complex ones, such as the one available at the CodingDojo KataTexasHoldEm

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.