.
Edited: 2011-02-05, 10:48 am
).
WPF is a terrible, terrible thing to learn as part of your first exposure to programming. I strongly recommend learning something like Python instead.
int i = 0;
while (i <= 3)
{
randomBlock = GetRandomBlock();
if (!randomBlock.NextToCircle())
{
randomBlock.AddCircle();
i++;
}
}IceCream Wrote:@JimmySeal:Grid: Look into multidimensional arrays.
thanks for the basic layout of the code! umm, i have no idea how to get it to pick a grid square at all, put the circle inside, or know whether there's any circle in the square next to it though :\
wccrawford Wrote:If I were teaching someone to program today, C# would probably be the language I'd pick, despite not having used it for years now. It's got an excellent (free) IDE, lots of community, good syntax, it's made for GUI stuff... Pretty much everything I'd ask for.There are a few problems with C# though

thurd Wrote:There are a few problems with C# thoughIn what ways is C# inferior to Java, pray tell?
1. It's a cheap & inferior rip-off of Java
2. Microsoft is satan
JimmySeal Wrote:Let's not start this here. This thread is about IceCream learning how to program. No elitism necessary.thurd Wrote:There are a few problems with C# thoughIn what ways is C# inferior to Java, pray tell?
1. It's a cheap & inferior rip-off of Java
2. Microsoft is satan
IceCream Wrote:Nobody else will have to modify my programs, so the benefits of using the language everyone else is using (being able to copy bits of code from existing programs, or ask for help if i'm really stuck) i guess should be weighed up against how difficult the language is to learn. I'd like to be self-sufficient as much as possible, and be able to write programs fairly quickly when i think of ideas for experiments. But it could be anything, so i need to use a language that has good flexibility & that i can control lots of different things.I think VB.NET vs. C# is really a matter of preference and neither is much harder to learn than the other. Both have the same sets of features (where it matters) because they operate on top of the .NET framework. There is interoperability between them, in that if one of your colleagues compiles a bunch of functionality into a DLL and gives it out, you can utilize that regardless of which .NET language you're using.
int[,] grid = new int[3, 3]; /* C# Code */
const int empty = 0;
const int occupied = 1;
/* You can use a loop to assign all the spaces their value initially,
but I'm just going to do them one by one here */
grid[0, 0] = empty;
grid[0, 1] = empty;
grid[0, 2] = empty;
grid[1, 0] = empty;
grid[1, 1] = empty;
grid[1, 2] = empty;
grid[2, 0] = empty;
grid[2, 1] = empty;
grid[2, 2] = empty;
/* The above can be thought of as:
[0, 0] [0, 1] [0, 2]
[1, 0] [1, 1] [1, 2]
[2, 0] [2, 1] [2, 2]
and right now, all cells would be empty:
[X] [X] [X]
[X] [X] [X]
[X] [X] [X]
*/
grid[0,1] = occupied;
grid[2,2] = occupied;
/* Now:
[X] [O] [X]
[X] [X] [X]
[X] [X] [O]
*/battlehymnz Wrote:I think you should focus on just using text to display your output. Once you get the logic code down, setting it up in a GUI won't sound nearly as difficult as it does now.Yeah. A lot of programming is about breaking down problems properly so that you can deal with it one tiny bit at a time. Otherwise complexity in one area will spread its tentacles through the entire program and it'll be impossible to understand.
class Node
{
// List of nodes that are next to this one
List<Node> nextNodes;
// bool to indicate whether or not this node is circled
public bool IsCircled = false;
// Returns true if there is a node next to this one that is circled
public bool IsNextCircled()
{
foreach (Node node in nextNodes)
{
if (node.IsCircled)
{
return true;
}
}
return false;
}
}chamcham Wrote:Considering that we need to make 3 points here's what to do (for a 4x4 square).You will never generate this configuration:
Point A= random point in the square
Point B = take point A and move 2 or 3 (chosen at random) points in the x-direction
Point C = take point A and move 2 or 3 (chosen at random) points in the y-direction
from random import randint
def dist(p1, p2):
return max(abs(p1%4-p2%4), abs(p1/4-p2/4))
available = range(16)
for i in range(3):
pick = available[randint(0, len(available)-1)]
available = [x for x in available if dist(x,pick) > 1]
print pickiSoron Wrote:I wasn't assuming wrap around and even stated that.chamcham Wrote:Considering that we need to make 3 points here's what to do (for a 4x4 square).You will never generate this configuration:
Point A= random point in the square
Point B = take point A and move 2 or 3 (chosen at random) points in the x-direction
Point C = take point A and move 2 or 3 (chosen at random) points in the y-direction
● ○ ○ ○
○ ○ ● ○
○ ○ ○ ○
○ ● ○ ○
And if you are unlucky, you may end up with two adjacent points:
○ ● ○ ○ Three ← steps results in ○ ● ● ○ (assuming you wrap around)
EDIT: Here's a python implementation. Squares are numbered from 0 to 15 like this:
0 1 2 3
4 5 6 7
8 9 10 11
12 13 14 15
Code:
from random import randint
def dist(p1, p2):
return max(abs(p1%4-p2%4), abs(p1/4-p2/4))
available = range(16)
for i in range(3):
pick = available[randint(0, len(available)-1)]
available = [x for x in available if dist(x,pick) > 1]
print pick