Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
First a bit of background information. I am playing an online campaign of D&D and am playing a druid. I already build an animal-tracker, for all my summoned animals, but now I want to speed things up a bit more by building a character tracker, for my own character, Duncan, as well as for my Mighty Eddy (dire-wolf animal companion).
The thing I am now working on, is keeping track of my spells. In D&D spells and spell levels are based on the level of the character and bonus stats.
For Druid: http://www.dandwiki.com/wiki/SRD:Druid
For Bonusses: http://www.dandwiki.com/wiki/SRD:Ability_Scores
Scroll down for Ability modifiers, so the more wisdom, the more spells.
Now, I am thinking of making tab-controlled pages, for spells ranging from level0 to level9 and then displaying ComboBoxes to select the spell(s) you want to prepare.
Innitially, I was planning on hiding the vast majority of comboboxes and only unhiding them with simple If statement, so if wisdom is high enough, unhide x amount of combo boxes....but that will mean creating loads of IF statements.
Is there a way to say, IF Wisdom is high enough for 10 spells, display 10 combo boxes, if wisdom is high enough for only 5, display only 5?
Or does anyone else have a good alternative idea on how to do this? I am open for suggestions.
NOTE: since you didn't specify a language or a platform I'm going to use C# and Windows Forms.
Sure, I'm not sure how you determine the wisdom level, but let's say it's stored in a variable named _wisdomLevel:
private int _wisdomLevel;
now you just need a Dictionary to handle that:
private Dictionary<int, int> _wisdomLevelSpells = new Dictionary<int, int>
{
{ 1, 5 },
{ 2, 5 },
{ 3, 10 },
}
Now, the values I put in there are random, they are so you can get the idea. Now to display those combo boxes I might do something like this:
for (int i = 0; i < _wisdomLevelSpells[_wisdomLevel]; i++)
{
this.Controls.Add(new ComboBox()
{
DataSource = ...,
ValueMember = ...,
DisplayMember = ...,
}
}
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I am creating a POS system using windows forms for a school project and would like to be able to add decimals together using the code in a button and come up with a total as the output at the end... any ideas on how this can be done?
If following doesn't answer your questions, please edit your post by elaborating your question.
Two questions I get so far.
Add a decimal to an undetermined length array.
Generally using List in C# if data keeps growing.
// Put this as your member variable
List<decimal> m_ItemPriceInOrder = new List<decimal>;
// In your button event
decimal price = ... // Get your price of item
m_ItemPriceInOrder.Add( price );
To sum up cost of items when checkout.
Using foreach to iterate through every item in your list.
Also a simple for loop is okay, but foreach represents "iterating through every item".
decimal sum = 0;
foreach( var item in m_ItemPriceInOrder ){
sum+=item;
}
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
I am trying to make a program to randomize entries for an event. I have the program working well enough for entering the entries but I'm stuck at randomizing it.
I have 2 lists, let's call one Head and the other one Heel. I have the lists as follows:
Head: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
Heel: [1a, 2a, 3a, 4a, 5a, 6a, 7a, 8a, 9a, 10a]
I want each item in the Head to have 2 random partners from Heel, but no value from Heel can be matched more than twice at the end of it all. In the final output, each entry should be listed twice and only twice.
Hopefully someone understands and is able to help me, thanks.
I feel like I need to go take a long bath, I feel so dirty for having this piece of code see the light of day, but something about OP's logic was mezmerizing. Anyway, 3 AM me thinks this should work:
var head = new List<char>("abcdef");
var heel = new List<char>("123456");
heel = heel.Concat(heel);
var randomer = new Random();
foreach (var knownItem in head)
{
var idx1 = randomer.Next(heel.Count);
var pair1 = heel[idx1];
heel.RemoveAt(idx1);
char pair2='\0';
while (true)
{
var idx2 = randomer.Next(heel.Count);
pair2 = heel[idx2];
if (pair2 != pair1)
{
heel.RemoveAt(idx2);
break;
}
}
//DoTheDew
}
Next steps for tomorrow: dieharder test the results of this version vs #Arj
Here's a possible solution. Since there's no code to start with, I've done it in pseudocode for now.
Create two Lists, each having all of the values in heel; call them heel1 and heel2
For each element i in head:
Generate a random number j where 0 <= j < heel1.size. Remove the element at heel1[j] - that's your first pairing
Repeat with heel2 (for a different generated j). Remove that element at heel2[j] - that's the second pairing
Store i along with the two removed values
By the end you will have two numbers for each value in head, with no value from heel appearing more than twice. Since we are removing any used values each time, we don't need to check for your "more than two pairings" rule.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
Good day all. Say I have a question:
What is a reverse reaction?
And the answer to this question is:
A reverse reaction is a reaction in which the products react to form
reactants and vise versa.
Now what would be the best way to determine if a user-inputted answer this question is correct or not? I can think of a couple of ways but they aren't practical.
One of the ways:
string answer = "A reverse reaction is a reaction in which the products react to form reactants and vise versa.";
string input = Console.ReadLine();
if (input.Equals(answer))
{
//answer is correct
}
Other way:
Checking to see how many words match and getting a percentage from that. If it calculates to a certain percentage then the answer is right.
Number of words: 17
Number of words in input that match answer: 17
Correctness percentage: 100%
Another way:
Check to see if the input contains certain key phrases.
string input = Console.ReadLine();
string[] keyPhrases = new string[] { "Products react to form reactants" };
foreach (string keyPhrase in keyPhrases)
{
if (!input.Contains(keyPhrase))
{
//answer is incorrect
return;
}
}
If what you mean by correctness is semantically correct, and the user is free to put up his answer, then I believe there is no simple way at this moment to do that by programming at all.
If you do it with the first way:
string answer = "A reverse reaction is a reaction in which the products react to form reactants and vise versa.";
string input = Console.ReadLine();
if (input.Equals(answer))
{
//answer is correct
}
And the user forgot to put the last little dot ".",
"A reverse reaction is a reaction in which the products react to form reactants and vise versa"
then he will get wrong, but he is actually correct
If you do it the second or the third way, then if the user simply mentions its negation, he may have high percentage of match but totally wrong in his concept:
"A reverse reaction is NOT a reaction in which the products react to form reactants and vise versa"
As of now, I believe the best way to do this is by restricting the user inputs to multiple choices provided by you.
And one of the best items to do this is the radio buttons. But you could do this by combo box and button or ListBox which allows single/multiple choices as you want it, but the bottom line is the same:
restrict your user inputs or you cannot tell whether his answer is semantically right/wrong easily.
It may require expertise in grammatical understanding, lots of dictionary words, complex words-meanings relationship models, and excellent background contexts interpretations otherwise.
That being said,
Regex cannot help to check if an answer is semantically correct - it can only help you to find a pattern which you may use to check if the user puts a semantically correct answer.
Thus...
If it is used together with human inspection, then probably your second and third ways + Regex would give some benefits.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I have a table with userid's (int increment) about 4M records.
I would like to show a new feature to only 25% of the users.
What would be the best way to choose those 25% users?
you could use some sort of Fisher Yates shuffle algorithm to randomly choose the 'first' 25% of user ids.
ie, pick a random number between 1 and 4M. that's your first user, add it to a collection somewhere. repeat until you have 1M (25%) users in your collection.
Once you have all the users, mark them somehow in your table.
Another idea is that you could set a browser cookie which was 'myAwesomeFeature=A' or 'myAwesomeFeature=B'. If the cookie isn't set yet, set it to 'B' if a random number between 0-100 is 25 or less. 'A' otherwise. If the cookie is already set, just use it.
Has the added benefit of being easily testable since you can easily force yourself to be in whichever group you want. And it'll work for multiple features since you just need to change the cookie name. And the same user will get the same group as long as the cookie doesn't expire.
How about this?
if (user.Id <= (maxId * 0.25))
{
// Show a new feature
}
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Improve this question
I'm working on an automated follow up system on highly antiquated techniques of registering the current status of a "Project" the GUI interaction in this system uses what are named "flags" that the user can "check" to designate the current status of a project. There are 11 possible boxes that can be checked and the system accepts multiple selections.
For example a user can select a check-box labeled "Confirmed" and or "Needs Follow Up" and or or "Is Scheduled" and or "Spoken with client" (There are 11 possible selections).
Here is the problem - whoever wrote this saved those selections to the database in a "bit sum" so the what you see is an int of the original bit[] for the check-box selections.
What I need to do is read the integer from the database and turn it back into a bit array of 11 values of 1 || 0 then from that bit array i need to determine which boxes of string value are checked in order to determine weather or not i need to perform an automated follow up.
So basically if "Confirmed" is checked i don't want to follow up
If "Needs-followup" is checked i need to follow up.
The problem here is that multiple selections can be present.
So after the int is turned into a bit[] we have for example
1,0,1,0,0,0,1,1,1,0,1 where each int represents a box checked.
i need to find a way to turn the above into an array of strings representing the box labels to determine which boxes are checked.
The usual way to do this in C# would be to use a flags enumeration - this is exactly what your bit field is.
[Flags]
enum ProjectStatus
{
Confirmed = 1,
NeedsFollowUp = 2,
SpokenWithClient = 4,
....
}
To test if a specific flag is set:
ProjectStatus status = (ProjectStatus)intFromDb;
if( ( status & ProjectStatus.Confirmed ) == ProjectStatus.Confirmed )
// the Confirmed flag is set
There is also a Enum.HasFlags extension method that simplifies this if you are in .NET 4 or higher.
If you do not wish to do it this way, you can find out if the bit at position x is set by doing this:
bool isSet = ( intFromDb & ( 1 << x ) ) != 0;
And use that to build your string.
Edit: I'd also suggest you read up a bit on bitwise operators and what they do. This might be a good start: http://blackwasp.co.uk/CSharpLogicalBitwiseOps.aspx