Comments (3)
Card of Rank 0 is Ace.
Line 29 in 9e34f47
Note that the ranks do not necessarily correspond to the values of a card - e.g. 1 for Ace, as those are different for every game.
If you want to add values to a card, I suggest writing a custom function in your own package. Something like valueOf(c decks.Card)
.
And if you want to check whether a card you got is of a certain rank, you can do:
if (c.Rank == decks.Ace) {
// handle Ace
}
Or a range:
if (c.Rank >= decks.Two && c.Rank < decks.Ten) {
// handle cards [2, 10)
}
from decks.
why not starting in iota+1? that would cover the value for most cases
from decks.
The initial implementation used that, yes.
But eventually, I decided to change it as it is now, because that approach causes issues with iterating over cards.
If the Ace starts at value 1, not zero, then there are all sorts of off-by-one errors that could occur.
For example, let's say you want to iterate over all ranks. Intuitively, you might do something like this:
cards := make([]Card, decks.RanksCnt)
for i := 0; i < decks.RanksCnt; i++ {
cards[i] = decks.Card{Rank: i}
}
Issues with the code above if Ace starts at 1:
- Rank of zero is invalid
- You won't include the last rank (King)
Even if you do:
cards := make([]Card, decks.RanksCnt)
for i := decks.Ace; i < decks.RanksCnt; i++ {
cards[i] = decks.Card{Rank: i}
}
This is still wrong, because you will miss the last rank (King) as decks.King == decks.RanksCnt
from decks.
Related Issues (1)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from decks.