Experience & Level Table [closed] - c#

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 9 years ago.
I'm working on a small self learning project with an EXP/Level calculator for a game and I just need a little advice.
I'm wondering what would be the best storage method to store a Level (1, 2, 3 up to 110) and an experience requirement for that level. I would like to be able to search for the level by an exp value, for example if level 9 is 1000 XP, and level 10 is 2,000 XP I'd be able to search for level 9 by inputting an XP value of 1000 - 1999.
So far I've researched SQL/List/Dictionary/Arrays and all seem good, but I can't find something that performs the operation I described.

Since the number of levels is only up to 110, you could just keep the ranges in an ordered list or array like so:
0
100
200
400
600
800
1000
1300
1600
and so on (I made up those numbers of course!)
Then you could search for the level for a particular XP value by either linearly searching the list (which would be fast enough probably) or if you really needed to you could use Array.BinarySearch() to find the nearest level, and do a check of the values to either side to see which band the XP falls into.
The level will just be the index of the found band + 1 (since levels start at 1, not 0).
To linearly search for the level for an XP value:
int[] xpArray = new [] { 0, 100, ... etc }// The list as shown above
int targetXP = 850;
int level = 0;
while ((level < xpArray.Length) && (targetXP > xpArray[level]))
++level;
// Now you have the right level.
Obviously this is just a brief overview to get you started! Also, you might need to adjust things slightly; I don't know your exact requirements. Does a character with 0 XP have level 0, for example?
The key thing to take away from this is the concept of searching a list of numbers, and using the index of the band that you find as a basis for the level, and also the fact that you only need to store one number for each band. You don't need to store a min and max value for each band, nor do you need to store the level. Those values are implicit.
I leave using Array.BinarySearch() to speed things up as an excercise for the reader... ;)

Related

Adding two different digit Numbers in c# ( without using BigInteger) [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
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.
Closed 9 years ago.
Improve this question
I have a Task to do C#. I need to add two numbers.
The first number contains around 100 digits like "12822429847264872649624264924626466826446692............"
and second number also with 100 digits or more or less
by using this numbers i need task like add/sub/multiply/div
I done this using BigInteger in C#
But do I need to do this using arrays or strings?
Since they are both 100 digits just start with the last digit and in a for loop just add each one, but if the value is > 10 then remember to add one to the next digit.
This is how children learn to add, you just need to follow the same steps, but the answer should be in an array of 101 characters.
UPDATE:
Since you have shown some code now, it helps.
First, don't duplicate the code based on if str1 or str2 is larger, but make a function with that logic and pass in the larger one as the first parameter.
Determine the largest size and make certain the smaller value is also the same size, to make math easier.
The smaller one should have leading zeroes (padding), again to help keep the code simple.
You can also start by looking at the source code for structures such as BigInteger. They would provide you more insight into aspects such as computational efficiency and storage, particularly about multiplication and division. You can take a look at here or here.

I need to convert a bit[] into an [] of strings that represent each bit in the bit[] [closed]

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

Generating unique but readable names in C# [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
I am trying to write a service in which every user will be assigned a unique name, when he first uses the service. I wish to generate this name, rather than getting the user to set it up. Also, I want the name to be somewhat readable and memorable rather than sound like a GUID or a timestamp. Essentially I want this to be something like the Xbox gamertag.
I know that there will never be more than a 1000 users so maintaining the uniqueness would not be a problem (another reason why I can afford to avoid GUIDs)
I am thinking of taking some adjectives, nouns etc. from the dictionary and generating random but unique combinations of those.
Any suggestions?
You could use a corpus of English language n-grams (say of three letter sequences) and use them to generate words that look like English, but are actually completely gibberish. This kind of data is essentially random, but has a softness for the nature of human language and memory.
This is similar to what I'm talking about, except it combines entire words into sentences probabilistically. I was thinking more of doing it by composing letter sequences into imaginary words.
EDIT actually this page discusses what I'm talking about.
This is just a code example to fully approach your problem. In case it doesn't solve it, please try to be more specific in your question. Pass to the following method an instance of the System.Random class and a list of words (your dictionary).
static string GetGuid(Random random, IList<string> words)
{
const int minGuidSize = 10;
const int maxGuidSize = 15;
var builder = new StringBuilder();
while (builder.Length < minGuidSize)
builder.Append(words[random.Next(words.Count)]);
return builder.ToString(0, Math.Min(builder.Length, maxGuidSize));
}
You can use this list of 10 000 random name:
http://www.opensourcecf.com/1/2009/05/10000-Random-Names-Database.cfm
or use this website to generate a random list of firstname:
http://www.fakenamegenerator.com/order.php
Safe way. maintain the list of remaining non used names.
Easy way (also very scalable) but unsafe. Rely on the unlikelyhood that 2 users randomly get the same id.
I would try to get 3 or 4 lists of about a thousand modalities and then randomly picking one value in each list. That would make about 10E12 possibilities which is enough to avoid collision for 1000 users.
JohnLampMartin2212

Looking for an alternative to this array solution [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
I have array of int[10000].
I need to sum each int with other one, and show result, for only those, where sum are > N.
Sum, can be any with any element of array, also sum of 5,6,7...10000 elements of array which > N.
I can write down(all combinations, but it`s insane) it like a[1] + a[2] + a[3]... But may be there are other resolution?
I need result all combinations, that gives me sum which is >N
Okey. If it is array of int[10]?
Your problem is similar to Subset Sum problem. Here you can find two solutions for this algorithm. The only change is you have to track your numbers whose sum is greater that N and you need to repeat it for all possibilities instead of just finding true/false result.

What's the difference between data Validation and Verification? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
My recollection from a past employer is that they distinguished between the two as follows:
Validation is the process of checking that the data is appropriate in a very basic sense; for example that data in a date field can be converted to a date, or that characters in a number field can be converted to a number of the appropriate type;
Verification is the process of checking the typed data against some other 'business' rules that you impose on your interface - for example that the Date Of Birth field indicates an applicant within a certain age range.
These memories do not tie in with the Wikipedia article on the subject, nor a BBC BiteSize Revision article.
So what is the consensus: Do people care what methods and processes are called when I am checking Xml inputs for example?
What am I doing when I:
Check that a date field contains characters that are convertible to a C# DateTime;
Check that the DateTime is in an appropriate date range to be stored in SQL Server;
Check that the Date Of Birth indicates a customer over 18 but under 65?
In my vocabulary, validation is checking whether the format of the data is correct, IE if a you're actually dealing with a correctly formatted date string . Verification is checking whether the date you got is actually the date you were expecting.
Ok, so I'll take this as an open invitation to musing...
I think the difference is very much like compile-time vs. runtime errors. Just like the compiler is able to tell that two variables a,b are of type double, and thus the expression a/b is valid, it is only during runtime a DivideByZeroException may be raised if b turns out to be 0.
So to complete the analogy, one can validate that a string looks like a credit card number ('compile time'), but can only verify that it corresponds to a valid card only if one tries to charge the credit card ('runtime') with an amount
Duh. So I guess I understand it pretty much like you old company does.
in terms of programming it makes no difference what you call it (validation or verification) but where you put the logic is important. usually all three rules you mentioned are known to be validations with first two points corresponding to UI validation and last point to business rule validation. we usually validate UI fields using dataannotations in our controller and Business rule validation is performed within business layer. But the bottom line from software point of view is; don't do an operation (save, edit) unless data is good (you call it valid or verified).

Categories

Resources