I am trying to program an iPhone App that will create a card set of 10 cards.
The total deck includes about 100 cards with different properties:
Each card has a name, a suit and a cost.
For an example:
card.name = "Test"
card.cost = 2
card.suit = "BasicSet"
Let's suppose there are 4 "Sets"* with 20 cards each.
I want the user to be able to select the suit themselves, because most of the suits come from extension sets.
To make it more balanced, I will also decide a maximum and minimum amount of cards with a specific cost (the cost ranging from 2 - 6).
In the end, there will be 2 functions. One function that selects all valid cards (from the available card suits) and another that picks 10 cards at random (taking into account the cost).
What is the easiest way to implement the cards? Defining the class card and implementing the 100 cards? Or creating 3 arrays with name, cost and origin where one card has the same index in all 3 arrays?
Help would be appreciated?
EDIT:
Each Suit contains unique cards. So if my suits are diamond, spade and so on, there will only be a diamond king, but no spade king.
Just an example how it could look like:
Suit Basic {
name=Village, cost=2
name=City, cost=3
name=NewYork, cost=6
}
Suit Advanced {
name=Tree, cost=4
name=Forest, cost=5
}
Suit Special {
name=Cocktail, cost=2
name=OrangeJuice, cost=4
}
One class Card could store all necessary information and functions for basic operations. When Card class is ready, you could create objects of that class with your data parsed from plist or any other format. It's not really necessary to hardcode your data inside the app.
Related
I am new to modelica, and i don't have this much experience in it, but i got the basics of course. I am trying to model a micrfluidic network. The network consists of two sources of water and oil, controlled by two valves. The flow of the two mediums interact at a Tjunction and then into a tank or chamber. I don't care about the fluid properties of the mixture because its not my purpose. My question is how do redeclare two medium packages (water and oil) in one system component such as the Tjunction or a tank in order to simulate the system. In my real model, the two mediums doesn't meet, becuase every medium passes through the channels at a different time.
I attached the model with this message. Here's the link.
https://www.dropbox.com/s/yq6lg9la8z211uc/twomediumsv2.zip?dl=0
Thanks for the help .
I don't think you can redeclare a medium during simulation. In your case (where you don't need the mixing of the two fluids) you could create a new medium, for instance called OilWaterMixture, extending from Modelica.Media.Interfaces.PartialMedium.
If you look into the code of PartialMedium you'll see that it contains a lot of partial ("empty") functions that you should fill in in your new medium model. For example, in OilWaterMixture you should extend the function specificEnthalpy_pTX to return the specific enthalpy of your water/oil mixture, for a certain water/oil mixture (given by the mass fraction vector X). This could be done by adding the following model to the OilWaterMixture package:
redeclare function extends specificEnthalpy_pTX "Return specific enthalpy"
Oil = Modelica.Media.Incompressible.Examples.Essotherm650;
Water = Modelica.Media.Water.StandardWater;
algorithm
h_oil := Oil.h_pT(p,T);
h_water := Water.specificEnthalpy_pT(p,T);
h := X[0]*h_oil + X[1]*h_water;
end specificEnthalpy_pTX;
The mass fraction vector X is defined in PartialMedium and in OilWaterMixture you must define that it has two elements.
Again, since you are not going to actually use the mixing properties but only mass fraction vectors {0,1} or {1,0} the simple linear mixing equation should be adequate.
When you use OilWaterMixture in the various components, the error log will tell you which medium functions they need. So you probably don't need to extend all the partial functions in PartialMedium.
I am trying to implement the DES circuit and according to a lot of papers, the S-boxes usually is implemented using a SRL or LUT, i'm not familiar with SRL, so i thought i use 8 LUT, each one has 6 adress lines and 4 data lines ( the 1st 2 adress lines represent the 1st and last bits of the bloc, and the 4 other adress lines represent the rest which will define the column)
For example if we take S-box 1 (shown in this figure)
Here is the table that comes with it
That's just for one box, it seems to me wrong, to do all of the boxes we have to write 512 lines. My first question is: is a LUT a hardware component? if so, i am using it correctly? and, is there a more appropriate implementation or representation?
My second question is: what does it mean hardware wiring? I found out that all the permutation function could be implemented using wire crossing, i didn't understand it. Should i make a wire for every bit?
In Genetic Programming (GP), when island model is used, does it mean that it will split the population size between islands?
For example, if in parameters file we have
pop.subpop.0.size = 4000
and we have 4 islands, does it mean that each island will have a population of size 1000? What if we put this line of code in parameters file of each island? Is it possible to have different population size for each island?
I'm using Java and ECJ package to implement island models in GP.
No, in your example you only have defined one island of 4000 individuals. The number is never automatically splited.
There are two ways to use Islands model in ECJ:
Using InterPopulationExchanger class:
One unique Java process that share variables. The islands are the subpopulations of the Population object. Therefore, you need to set sizes for each subpopulation in the parameter file. In your example, you only have set the island (subpopulation) 0 to 4000 individuals, but you should also set the other sizes. For example, for 10 islands of 4000 individuals each:
exch = ec.exchange.InterPopulationExchange
pop.subpops = 10
pop.subpop.0.size = 4000
pop.subpop.1.size = 4000
pop.subpop.2.size = 4000
...etc
pop.subpop.10.size = 4000
Using IslandExchanger class:
In this case, every island is executed in a different Java process, so, every islandID.params file (one per island/process) needs to set only one population:
exch = ec.exchange.InterPopulationExchange
pop.subpop.0.size = 4000
And the number of islands is set in the server.params file:
exch.num-islands = 10
You can see the rest of parameters and more information on page 223 of the ECJ documentation pdf: https://cs.gmu.edu/~eclab/projects/ecj/docs/manual/manual.pdf
I have not studied the ECJ package, but that is the general idea: you have a population which is divided in multiple subpopulations.
I don't know why you want subpopulations of different sizes. Is there a benefit compared to fixed-size subpopulations?
Anyway, I did a very simple implementation of a Genetic-Programming variant with multiple subpopulations. You can download it here: http://www.mepx.org/source_code.html
It is written in C++, but it should be very easy to understand by Java programmers.
I have a question regarding nested arrays of objects.
I’m writing a simple objective c program (I’m a beginner) and I was wondering whether it is advisable to structure an array in such a way that not only are all the individual batting scores be logged (data), but also methods embedded in the nested arrays could be used to interrogate the this data.
For example the line below is easily readable (even for those who are not cricket fans!)
Team1.Over[2].BowlNumber[3].score = 6
Team 1 scored a 6 during the 3rd bowl in the 2nd Over.
I would also like to do something like the following where I can use a method to interrogate the data. The method line below would just cycle through the scores within BowNumber[] and total the scores up
Total = Over[2].TotalForAmountForOver()
I could set up and manage all the arrays from within main() , but its much easier to read if I can embed as much as possible within the structure.
Is this a common approach?
Haven't seen many examples of fairly complicated embedded arrays of data and methods….
You'd easily be able to achieve this by making Over cant Bowl classes that each wrap an NSMutableArray object. e.g.
- (void)getOverNumer:(int)index {
return [overs objectAtIndex:index];
}
You'd then access it like this:
[[team1 getOverNumber:2] getBowlNumber:2].score = 6;
int total = [[team1 getOverNumber:2] totalForAmountForOver];
You'd implement totalForAmountForOver as a method within your Over class.
I'm wrangling with issues regarding how character equipment and attributes are stored within my game.
My characters and equippable items have 22 different total attributes (HP, MP, ATP, DFP). A character has their base-statistics and can equip up to four items at one time.
For example:
BASE ATP: 55
WEAPON ATP: 45
ARMOR1 ATP: -10
ARMOR2 ATP: -5
ARMOR3 ATP: 3
Final character ATP in this case would be 88.
I'm looking for a way to implement this in my code. Well, I already have this implemented but it isn't elegant. Right now, I have ClassA that stores these attributes in an array. Then, I have ClassB that takes five ClassA and will add up the values and return the final attribute.
However, I need to emphasize that this isn't an elegant solution.
There has to be some better way to access and manipulate these attributes, including data structures that I haven't thought of using. Any suggestions?
EDIT: I should note that there are some restrictions on these attributes that I need to be put in place. E.g., these are the baselines.
For instance, the character's own HP and MP cannot be more than the baseline and cannot be less than 0, whereas the ATP and MST can be. I also currently cannot enforce these constraints without hacking what I currently have :(
Make an enum called CharacterAttributes to hold each of STR, DEX, etc.
Make an Equipment class to represent any equippable item. This class will have a Dictionary which is a list of any stats modified by this equipment. For a sword that gives +10 damage, use Dictionary[CharacterAttributes.Damage] = 10. Magic items might influence more than one stat, so just add as many entries as you like.
The equipment class might also have an enum representing which inventory it slots to (Boots, Weapon, Helm).
Your Character class will have a List to represent current gear. It will also have a dictionary of CharacterAttributes just like the equipment class, which represents the character's base stats.
To calculate final stats, make a method in your Character class something like this:
int GetFinalAttribute(CharacterAttributes attribute)
{
int x = baseStats[attribute];
foreach (Equipment e in equipment)
{
if (e.StatModifiers[attribute] != null)
{
x += e.StatModifiers[attribute];
}
}
// do bounds checking here, e.g. ensure non-negative numbers, max and min
return x;
}
I know this is C# and your post was tagged VB.NET, but it should be easy to understand the method. I haven't tested this code so apologies if there's a syntax error or something.