Giter Site home page Giter Site logo

cactuskevlua's Introduction

CactusKevLua

CactusKev's Poker hand ranking implemented in easy to use Lua format. Accepts both 5 card and 7 card hands. Designed for Roblox

Example usage:

local HandEvaluator = require(script.Parent.HandEvaluator)

-- Define test cases
local testHands = {
	RF  = {"AC", "KC", "QC", "JC", "TC"},
	SF  = {"8C", "7C", "6C", "5C", "4C"},
	Q   = {"9D", "9C", "9H", "9S", "2C"},
	FH  = {"5D", "5C", "5H", "7S", "7H"},
	F   = {"2H", "4H", "6H", "9H", "JH"},
	S   = {"2S", "3H", "4S", "5C", "6D"},
	T   = {"KD", "KC", "KH", "3S", "4D"},
	TwoP= {"2D", "2C", "6S", "6H", "9D"},
	OneP= {"JC", "JD", "4H", "7C", "9S", "2H", "3H"}
}

local function convertToHandFormat(cards)
	local hand = {}
	for _, card in ipairs(cards) do
		table.insert(hand, {rank=string.sub(card, 1, -2), suit=string.sub(card, -1)})
	end
	return hand
end

-- Run the tests
for handType, cards in pairs(testHands) do
	local hand = convertToHandFormat(cards)
	local rank, handName = HandEvaluator(hand)
	print(handType, ":", rank, "-", handName)
end

print("All tests complete!")

Test output:

  17:32:31.297  SF : 7 - Eight-High Straight Flush  -  Server - test:28
  17:32:31.298  FH : 282 - Fives Full over Sevens  -  Server - test:28
  17:32:31.298  TwoP : 3254 - Sixes and Deuces  -  Server - test:28
  17:32:31.298  T : 1739 - Three Kings  -  Server - test:28
  17:32:31.298  RF : 1 - Royal Flush  -  Server - test:28
  17:32:31.298  F : 1438 - Jack-High Flush  -  Server - test:28
  17:32:31.298  S : 1608 - Six-High Straight  -  Server - test:28
  17:32:31.298  OneP : 4158 - Pair of Jacks  -  Server - test:28
  17:32:31.298  Q : 82 - Four Nines  -  Server - test:28

cactuskevlua's People

Contributors

adigitalfrontier avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.