Who wins the game? - vb.net

I am trying to define a function that returns a value indicating whether the winner of my game has been determined, if yes, who the winner is, and after the player's turn, update the remaining number of sticks and use the function defined above to check if a winner has been determined and if the game should continue.
I am creating a game in VB.NET that's called pick up sticks, it involves two players who take turns to play. Players can start with any number of sticks that they both agree upon before game. At each player’s turn, the player must pick at least one stick and at most half the sticks. Whoever picks up the last stick loses the game. I need to implement this game so that a player can play against the computer
This is me trying to write the computer's turn:
Private Sub ComputerTurn() 'change 6 with setNum whatever sticks number was agreed upon
Dim ComputerNum As Integer
'ComputerNum = Int((SetNumInputTB * Rnd()) - SetNumInputTB / 2)
MsgBox("The computer picked " & ComputerNum & " sticks")
End Sub
I think I should use an if statement or a for loop but I'm not sure how to implement the right mathmatics in it

Well you are going to need a lot more that just that in the computer turn. You will need to update how many sticks are left in the pile. Also depending on if you want the computer to play optimal strategy then you will have to add logic into the function.
Umm I do think that the game is pretty silly because the person who goes first wins every time. They pick up one less than half (ex start with 30). So they pick up 14 and 16 are left. Next turn the other player can pick up at most 15 and at least 1 stick so the next turn player one can clear the board except one stick
If you mean they can only pick up half the remaining pile the the logic will be a little more complicated but still not too bad.

Related

VB.Net - How do I find the position of several elements in an array where a condition is met

I'm a newbie programmer, and right now I'm creating a backgammon game in VB (a simple version right now which will be built up overtime).
I am trying to get the game to record how many checkers a player has, and where these checkers are on the board. The white checkers are represented as negative integers and black checkers as positive integers. Once this is done the player would be able to select which checker to move and where depending on their dice roll.
So my question is, how would I be able to record the element position in an array, for example, when the array is checked for values where the value is > 0 for the white checker player. I'll add my code for this section - sorry if my coding is poorly executed.
If possible dumb down the advice haha
Console.WriteLine("Make your first move: ")
For Each x In Gameboard
If x > 0 Then
Console.WriteLine("You have {0} pieces in position ", x)
End If
Next
You could, create a counter variable, above your loop, and increment it in each iteration, but that's a bit ugly. The preferable way to do it is to use a plain For loop, with a counter, rather than a For Each loop. For instance:
Console.WriteLine("Make your first move: ")
For i As Integer = 0 To Gameboard.Length
If Gameboard(i) > 0 Then
Console.WriteLine("You have {0} pieces in position {1}", Gameboard(i), i)
End If
Next
General rule of thumb:
If you need to know the index, use a For loop
If you don't need to know the index, use a For Each loop

How to create a stars review system in Excel for a table?

I am new in VBA, and I got a task to find a way to implement the 5 stars review like in Amazon/Ebay with graphical stars itself for an excel table. Is it possible that? or even to combine with other technologies.
All I need are some hits, how to do that, and where to start.
Based on your last comment I would like to merely sketch the basic concept of doing such rating manually. Since I couldn't fit it in a comment box I'll put it here as a conceptual draft of what it might look like (this is not an attempt to be a solution):
(1) Getting a star on a sheet is as simple as that
Sheet1.Shapes.AddShape Type:=msoShape5pointStar, _
Left:=100, Top:=100, Width:=7.2, Height:=7.2
(2) Getting four more stars next to it should be simple enough by adding the width of prior star(s) and some extra space to the Left.
(3) Color your star(s) yellow or white with presets (Office 2010+)
.ShapeStyle = msoShapeStylePreset12
(4) In order to locate the stars on the sheet next to the cell containing the value which should be rated you can use the following methods assuming that the value is in cell A1:
.Left = Sheets(1).Range("A1").Left + Sheets(1).Range("A1").Width
Of course, there is a bit more to it than the above. You will have to determine the range of cells for which you want to create stars. Also, if someone adds a column or changes the width of a column then all stars might get changed and will have to be drawn again. Also, you'll have to make sure that the column B is wide enough to hold all the stars. But that's the basic concept (as I would attempt to do it).

How to make a count-down function work in netlogo

I'm having some difficulty with my code for a bigger program in net logo that i am working on! I'm attempting to start at a count at 15 and then count down to zero, with cell death occurring at zero. For some reason, my turtles each start off at a different number and then instead of decreasing by 1 count per tick, they decrease by various increments until zero. i'm sure its a silly mistake that i should be catching but i'v been staring at the screen for a long time and am getting frustrated so figured i would reach out to my fellow programmers
You do not provide much context for you question, but here is an example that seems to meet your needs. Enter the code below in the Code tab and then enter setup go show [lifespan] of turtles at the command line.
turtles-own [lifespan]
to setup
ca
crt 20 [init-turtle]
end
to go
ask turtles [age]
end
to init-turtle
set lifespan 15
fd 5
end
to age
set lifespan (lifespan - 1)
if (lifespan <= 0) [die]
end

VB.Net Events Practice Help

I was given an assignment to "write a program to print only even numbers between 6 and 16 using events", but I don't even know where to begin. The main thing I am having difficulty with understanding in this assignment is how I am supposed to specify that it only print even numbers in the given range of numbers.
Am I going to have to do a Mod2 code for each individual number and have it exclude any with the result of 1? Or is there another piece of code specifically designed for such an occassion? Perhaps there is some type of equation I can have the program read in terms of a variable, which holds the values of 6, 8, 10, 12, 14, and 16? I am just genuinely confused on how this is supposed to be programmed. Any assistance would be greatly appreciated.
No offense, but I'm not at all convinced that you are accurately relaying you assignment, but...
Firstly, using MOD is a good starting point, particularly as you are supposedly tying this in with events...
To use events as part of your solution, I would suggest creating a textbox withevents and a handler for textchanged, then in a loop set the txtbox.Text property to the string representation of the loop index (say going from 1 to 20), then inside the textchanded event turn the propery back into an integer, check to see if it's within the proper range and even(using, as you suggested, MOD).
The following will help you solving a part of the problem:
Dim number as Integer = 6
While number <= 16
// PRINT Goes here ..
number = number + 2
End While
These Microsoft links are good learning resources:
Learning Visual Basic from the Ground Up
Getting Started with Visual Basic
Video How to: Creating Your First Visual Basic Program
Events in Visual Basic
Closer Look: Understanding Properties, Methods, and Events
Events and Event Handlers

Algorithm to find word on Boggle board

I'm building a boggle game in vb .net. Right now, my dices are as a 2d array (0,0 0,1 ) etc...
What I want it to do is, as I'm typing the word, that it highlights it on the board using the button(x,y).doclick sub which highlights it. Right now my implementation finds the first letter, then keeps trying each letter until it meets the 8 corner condition (ie it is neighbored to the last one) but this does not always work. If there are say 2 "G"'s on the board and I want the bottom one, this will not work. Can somebody give me an example of psuedocode of what needs to happen. I've been stumped for almost 6 hours trying to figure this out. Thanks
If I understand correctly, given a string you want to highlight one path through the dice that matches the string. Sometimes there are several possible choices, so adding a letter may completely change what is highlighted. It may be a good approach here to keep results from the previous substring, so we don't have to start over. Then a reasonable thing to do would be to compute all possible paths.
The answer for a given string s would be a list of paths, where a path is a list of grid coordinates. Each path is something you could reasonably highlight, so you just highlight the first one. When adding a letter to the string, you find paths you can expand and remove the ones you can't expand.
I'm afraid I don't know how to write vb code. Since you asked for pseudocode, here's some rough python-like pseudocode instead. I'm coding the boggle grid as a list of 16 items. The neighbors(x) function returns a list of the neighboring positions (except for edge cases that's going to be [x-1, x+1, x-4, x+4]).
def firstLetter(typed):
answer = []
for pos in range(16): if grid[pos]==typed: answer += [pos]
return answer
def addletter(partialanswer, typed):
answer2 = []
for partial in partialanswer:
for neighbor in neighbors(partial[-1]):
if grid[neighbor]==typed:
# partial+[neighbor] is a list. answer2 is a list of such lists.
answer2 += partial + [neighbor]
return answer2
If the player types "go", for example, then
(a) player types "g", code calls firstletter("g") and gets a list "answer" of the positions in the grid that have a "g" in them. Highlight, say, the first one.
(b) player types "o", code calls addletter(answer, "o") and gets a list of the paths in the grid that say "go". Again, highlight the first one.