So, I'm admittedly quite new to cocoa, and only half-way familiar with C to begin with, but I managed last night(till 4a.m.) to get my double elimination brackets app working, for the most part. But I hit a major problem.
The part that is killing me is a randomizer button, for the players in the tourny.
I have 16 "nplayerX" NSTextField's, which are used for name input, and to hold temporarily, before randomizing the names into 16 "playerX" NSTextField's that the app will actually use.
So, I dreamt up a way to make this work, but at 4 a.m. I dont have to question that it isn't the best way.
So the app does compile with only 2 warnings, the lines:
[randomName setStringValue:NSSelectorFromString([NSString stringWithFormat"player", @"%i", (i + 1)])];
[orderedName setStringValue:NSSelectorFromString([NSString stringWithFormat"nplayer", @"%d", (d +1)])];
Need to come up with a way to take a random number (i), and turn it into a binding(?) for "player(i)" and the for (d yadda yadda) so d can sit at the end of "player(d)"
Any brilliant coders know of a much simpler way to do this, or randomize a list in general?
Any help or insight would be lovely
-dj.mooky
Looking at this, I think I was onto something with making an array of names, and just doing 16 different small segments to make i random, name pnames = nplayer(1-16 in order) with a check statement to see if it's already taken, hmmm.... That does seem easier to my brain, but it is still broken from lack of sleep -- anyway.
code snippets:
*************************************
// TournyController.h
@interface TournyController : NSObject {
// Edit Names window fields
IBOutlet NSTextField *nplayer1;
IBOutlet NSTextField *nplayer2;
IBOutlet NSTextField *nplayer3;
IBOutlet NSTextField *nplayer4;
IBOutlet NSTextField *nplayer5;
IBOutlet NSTextField *nplayer6;
IBOutlet NSTextField *nplayer7;
IBOutlet NSTextField *nplayer8;
IBOutlet NSTextField *nplayer9;
IBOutlet NSTextField *nplayer10;
IBOutlet NSTextField *nplayer11;
IBOutlet NSTextField *nplayer12;
IBOutlet NSTextField *nplayer13;
IBOutlet NSTextField *nplayer14;
IBOutlet NSTextField *nplayer15;
IBOutlet NSTextField *nplayer16;
// for the randomizer
IBOutlet NSTextField *randomName; // represents playerX
IBOutlet NSTextField *orderedName; // represents nplayerX
// PlayerName *pnames[15]; // failed attempt, left it in for later attempts maybe
bool placecounter[15]; // mark if that name has been used already
// Main window fields
IBOutlet NSTextField *player1;
IBOutlet NSTextField *player2;
IBOutlet NSTextField *player3;
IBOutlet NSTextField *player4;
IBOutlet NSTextField *player5;
IBOutlet NSTextField *player6;
IBOutlet NSTextField *player7;
IBOutlet NSTextField *player8;
IBOutlet NSTextField *player9;
IBOutlet NSTextField *player10;
IBOutlet NSTextField *player11;
IBOutlet NSTextField *player12;
IBOutlet NSTextField *player13;
IBOutlet NSTextField *player14;
IBOutlet NSTextField *player15;
IBOutlet NSTextField *player16;
}
- (IBAction)randomizeNamesid) sender;
----------------------------------------
// tournycontroller.m
#import "TournyController.h"
@implementation TournyController
- (IBAction)randomizeNamesid) sender {
// randomizes names while still in entering screen, before putting them in brackets
// seed the random number generator with the time, to get new randoms
srand(time(NULL));
int d=0;
int i=0;
for ( i=0; i<15; i++ ) {
placecounter == false;
}
//force playerX to take nplayer values, so that nplayer values can be mixed up
[player1 setStringValue: [nplayer1 stringValue]];
[player2 setStringValue: [nplayer2 stringValue]];
[player3 setStringValue: [nplayer3 stringValue]];
[player4 setStringValue: [nplayer4 stringValue]];
[player5 setStringValue: [nplayer5 stringValue]];
[player6 setStringValue: [nplayer6 stringValue]];
[player7 setStringValue: [nplayer7 stringValue]];
[player8 setStringValue: [nplayer8 stringValue]];
[player9 setStringValue: [nplayer9 stringValue]];
[player10 setStringValue: [nplayer10 stringValue]];
[player11 setStringValue: [nplayer11 stringValue]];
[player12 setStringValue: [nplayer12 stringValue]];
[player13 setStringValue: [nplayer13 stringValue]];
[player14 setStringValue: [nplayer14 stringValue]];
[player15 setStringValue: [nplayer15 stringValue]];
[player16 setStringValue: [nplayer16 stringValue]];
// below is failed part of failed attempt.. I need to learn a little more about using arrays and classes it seems
// [pnames[0] setStringValue:[nplayer1 stringValue]];
// [pnames[1] setStringValue:[nplayer2 stringValue]];
// [pnames[2] setStringValue:[nplayer3 stringValue]];
// [pnames[3] setStringValue:[nplayer4 stringValue]];
// [pnames[4] setStringValue:[nplayer5 stringValue]];
// [pnames[5] setStringValue:[nplayer6 stringValue]];
// [pnames[6] setStringValue:[nplayer7 stringValue]];
// [pnames[7] setStringValue:[nplayer8 stringValue]];
// [pnames[8] setStringValue:[nplayer9 stringValue]];
// [pnames[9] setStringValue:[nplayer10 stringValue]];
// [pnames[10] setStringValue:[nplayer11 stringValue]];
// [pnames[11] setStringValue:[nplayer12 stringValue]];
// [pnames[12] setStringValue:[nplayer13 stringValue]];
// [pnames[13] setStringValue:[nplayer14 stringValue]];
// [pnames[14] setStringValue:[nplayer15 stringValue]];
// [pnames[15] setStringValue:[nplayer16 stringValue]];
// fix this ****! turn the string into something NSTextField can understand
i == (rand() % 15);
for (d=0; d<15; d++) {
while ( placecounter == false ) {
i == (rand() % 15);
}
[randomName setStringValue:NSSelectorFromString([NSString stringWithFormat"player", @"%i", (i + 1)])];
[orderedName setStringValue:NSSelectorFromString([NSString stringWithFormat"nplayer", @"%d", (d +1)])];
[orderedName setStringValue:[randomName stringValue]];
placecounter == true;
}
}
The part that is killing me is a randomizer button, for the players in the tourny.
I have 16 "nplayerX" NSTextField's, which are used for name input, and to hold temporarily, before randomizing the names into 16 "playerX" NSTextField's that the app will actually use.
So, I dreamt up a way to make this work, but at 4 a.m. I dont have to question that it isn't the best way.
So the app does compile with only 2 warnings, the lines:
[randomName setStringValue:NSSelectorFromString([NSString stringWithFormat"player", @"%i", (i + 1)])];
[orderedName setStringValue:NSSelectorFromString([NSString stringWithFormat"nplayer", @"%d", (d +1)])];
Need to come up with a way to take a random number (i), and turn it into a binding(?) for "player(i)" and the for (d yadda yadda) so d can sit at the end of "player(d)"
Any brilliant coders know of a much simpler way to do this, or randomize a list in general?
Any help or insight would be lovely
-dj.mooky
Looking at this, I think I was onto something with making an array of names, and just doing 16 different small segments to make i random, name pnames = nplayer(1-16 in order) with a check statement to see if it's already taken, hmmm.... That does seem easier to my brain, but it is still broken from lack of sleep -- anyway.
code snippets:
*************************************
// TournyController.h
@interface TournyController : NSObject {
// Edit Names window fields
IBOutlet NSTextField *nplayer1;
IBOutlet NSTextField *nplayer2;
IBOutlet NSTextField *nplayer3;
IBOutlet NSTextField *nplayer4;
IBOutlet NSTextField *nplayer5;
IBOutlet NSTextField *nplayer6;
IBOutlet NSTextField *nplayer7;
IBOutlet NSTextField *nplayer8;
IBOutlet NSTextField *nplayer9;
IBOutlet NSTextField *nplayer10;
IBOutlet NSTextField *nplayer11;
IBOutlet NSTextField *nplayer12;
IBOutlet NSTextField *nplayer13;
IBOutlet NSTextField *nplayer14;
IBOutlet NSTextField *nplayer15;
IBOutlet NSTextField *nplayer16;
// for the randomizer
IBOutlet NSTextField *randomName; // represents playerX
IBOutlet NSTextField *orderedName; // represents nplayerX
// PlayerName *pnames[15]; // failed attempt, left it in for later attempts maybe
bool placecounter[15]; // mark if that name has been used already
// Main window fields
IBOutlet NSTextField *player1;
IBOutlet NSTextField *player2;
IBOutlet NSTextField *player3;
IBOutlet NSTextField *player4;
IBOutlet NSTextField *player5;
IBOutlet NSTextField *player6;
IBOutlet NSTextField *player7;
IBOutlet NSTextField *player8;
IBOutlet NSTextField *player9;
IBOutlet NSTextField *player10;
IBOutlet NSTextField *player11;
IBOutlet NSTextField *player12;
IBOutlet NSTextField *player13;
IBOutlet NSTextField *player14;
IBOutlet NSTextField *player15;
IBOutlet NSTextField *player16;
}
- (IBAction)randomizeNamesid) sender;
----------------------------------------
// tournycontroller.m
#import "TournyController.h"
@implementation TournyController
- (IBAction)randomizeNamesid) sender {
// randomizes names while still in entering screen, before putting them in brackets
// seed the random number generator with the time, to get new randoms
srand(time(NULL));
int d=0;
int i=0;
for ( i=0; i<15; i++ ) {
placecounter == false;
}
//force playerX to take nplayer values, so that nplayer values can be mixed up
[player1 setStringValue: [nplayer1 stringValue]];
[player2 setStringValue: [nplayer2 stringValue]];
[player3 setStringValue: [nplayer3 stringValue]];
[player4 setStringValue: [nplayer4 stringValue]];
[player5 setStringValue: [nplayer5 stringValue]];
[player6 setStringValue: [nplayer6 stringValue]];
[player7 setStringValue: [nplayer7 stringValue]];
[player8 setStringValue: [nplayer8 stringValue]];
[player9 setStringValue: [nplayer9 stringValue]];
[player10 setStringValue: [nplayer10 stringValue]];
[player11 setStringValue: [nplayer11 stringValue]];
[player12 setStringValue: [nplayer12 stringValue]];
[player13 setStringValue: [nplayer13 stringValue]];
[player14 setStringValue: [nplayer14 stringValue]];
[player15 setStringValue: [nplayer15 stringValue]];
[player16 setStringValue: [nplayer16 stringValue]];
// below is failed part of failed attempt.. I need to learn a little more about using arrays and classes it seems
// [pnames[0] setStringValue:[nplayer1 stringValue]];
// [pnames[1] setStringValue:[nplayer2 stringValue]];
// [pnames[2] setStringValue:[nplayer3 stringValue]];
// [pnames[3] setStringValue:[nplayer4 stringValue]];
// [pnames[4] setStringValue:[nplayer5 stringValue]];
// [pnames[5] setStringValue:[nplayer6 stringValue]];
// [pnames[6] setStringValue:[nplayer7 stringValue]];
// [pnames[7] setStringValue:[nplayer8 stringValue]];
// [pnames[8] setStringValue:[nplayer9 stringValue]];
// [pnames[9] setStringValue:[nplayer10 stringValue]];
// [pnames[10] setStringValue:[nplayer11 stringValue]];
// [pnames[11] setStringValue:[nplayer12 stringValue]];
// [pnames[12] setStringValue:[nplayer13 stringValue]];
// [pnames[13] setStringValue:[nplayer14 stringValue]];
// [pnames[14] setStringValue:[nplayer15 stringValue]];
// [pnames[15] setStringValue:[nplayer16 stringValue]];
// fix this ****! turn the string into something NSTextField can understand
i == (rand() % 15);
for (d=0; d<15; d++) {
while ( placecounter == false ) {
i == (rand() % 15);
}
[randomName setStringValue:NSSelectorFromString([NSString stringWithFormat"player", @"%i", (i + 1)])];
[orderedName setStringValue:NSSelectorFromString([NSString stringWithFormat"nplayer", @"%d", (d +1)])];
[orderedName setStringValue:[randomName stringValue]];
placecounter == true;
}
}