Forum
A place to discuss topics/games with other webDiplomacy players.
Page 666 of 1419
FirstPreviousNextLast
Enzyme (100 D)
16 Oct 10 UTC
Can someone explain what just happened?
New to the site, and I'm having some trouble interpreting the symbols/rules. I'm *NOT* looking for advice, just an explanation of what happened.
5 replies
Open
Le Masticateur (119 D)
15 Oct 10 UTC
Question About Retreating
I have a question regarding the rules of retreating. I'm new to this game and I didn't venture to read all of the threads, so I'm sorry if this topic was already reviewed.
5 replies
Open
basvanopheusden (2176 D)
16 Oct 10 UTC
a great gunboat game
To all in this game, well played.
3 replies
Open
fuzz (0 DX)
16 Oct 10 UTC
need 1 more like rite now
1 reply
Open
Z (0 DX)
13 Oct 10 UTC
Question for Programmers
Im making an array, and I insert a value at a point in the array, and any unused area is assigned a zero. eg [7,3] and each previous cell gets a zero. My question is how do i write a method that deletes the excess zeros, but keeps the value. Later on, ill have to have it delete zeros when i have information in the first, third, seventh cell etc, and the rest are filled with zeros.
Page 3 of 4
FirstPreviousNextLast
 
figlesquidge (2131 D)
15 Oct 10 UTC
Yes hello to those above responding to me. I was merely wondering on efficiency as noted, if only as a number of neat solutions had already been given to the main problem.
kestasjk (95 DMod(P))
15 Oct 10 UTC
If no-one has already done it I think it's probably optimal to keep two pointers, one to the next available empty position, one to the current position being checked;

for(int current=0, available=0; current<array.length; current++) {
_if(array[current]!=0) {
__array[available]=array[current];
__available++;
_}
}
kestasjk (95 DMod(P))
15 Oct 10 UTC
forgot also needed to clear out the rest:
do {
_array[available]=0;
} while(++available < array.length);
Should still be O(n) though, if it works
kestasjk (95 DMod(P))
15 Oct 10 UTC
<?php

$array = array();
for($length=0; $length<1000; $length++)
$array[] = rand(0,1);

print 'Unsorted: '.implode(', ',$array).'
';

for($current=0, $available=0; $current<$length; $current++)
if ( $array[$current] != 0 ) {
$array[$available] = $array[$current];
$available++;
}

do {
$array[$available]=0;
} while ( ++$available < $length );

print 'Sorted: '.implode(', ',$array);

die();
?>

Yay, what do I win?

.. oh :-|
orathaic (1009 D(B))
15 Oct 10 UTC
if you can sort in php faster than the C# you get a cookie...
kestasjk (95 DMod(P))
15 Oct 10 UTC
<?php

$array = array();
for($length=0; $length<1000; $length++)
$array[] = rand(0,1);

print 'Unsorted: '.implode(', ',$array).'
';
sort($array);
print 'Sorted: '.implode(', ',$array);
?>

(p.s. before this becomes a silly language war I prefer C# to PHP generally, but for 10-liners PHP is easier)
Draugnar (0 DX)
15 Oct 10 UTC
But this wasn't a sorting algorithm. He just wants "white space" values removed.

But I agree with Kestas that a double counter is the *most* efficient means to do this.

Kestas +1
figlesquidge (2131 D)
15 Oct 10 UTC
Slight aside, but what language are the php core functions written in?
Draugnar (0 DX)
15 Oct 10 UTC
Probably C++, or Perl which was written in C++ considering PHP is basically scripted Perl.
Alderian (2425 D(S))
15 Oct 10 UTC
Actually, if you are using a basic C array, it would be faster to use actual pointers so you aren't doing so much pointer arithmetic each time you use [ ]. Also, ++variable is faster than variable++ so might as well use it when you don't need the original value returned.

I would go with something like this if efficiency is really important.


short array[1000];

// randomly fill array here!!!
//

short * current = &array;
short * available = current;
short * end = current + countof(array);

for ( ; current < end; ++current)
{
__if (*current != 0)
__{
____*available = *current;
____++available;
__}
}

for ( ; available < end; ++available)
{
__++available;
}
Draugnar (0 DX)
15 Oct 10 UTC
I had never heard the pre increment was faster than post increment. Is that true? And have you tried running this? You have tow unattached for loops (i.e. they aren't nested). I don't think it will work.
figlesquidge (2131 D)
15 Oct 10 UTC
Yeh sorry, quick google says it is C, with many of the extensions in C++
Alderian (2425 D(S))
15 Oct 10 UTC
My code is just a minor modification of kestas' code to use pointers instead of indexes. But I did totally mess up my second loop. Should be...

for ( ; available < end; ++available)
{
__*available = 0;
}

In any case, think about what ++var does versus var++. ++var just increments the value and returns it. var++ has to store aside the original value, then increment the variable, and then return the original value.
Alderian (2425 D(S))
15 Oct 10 UTC
By the way, am I the only one here who puts the { on a new line? I really dislike having them at the end of the line.
orathaic (1009 D(B))
15 Oct 10 UTC
no language war, though i was going to write the cookie generating script in php, if that is seen as language bias then so be it! :'(

and Ald, i prefer your, {} on new lines, style. Though i don't think the forum is the best place to try it out...
kestasjk (95 DMod(P))
15 Oct 10 UTC
> Slight aside, but what language are the php core functions written in?
Yup C & C++, a weakness in terms of security but often a strength in terms of speed

> Probably C++, or Perl which was written in C++ considering PHP is
> basically scripted Perl.
I don't think Zend has ever used anything remotely related to Perl, except perhaps Perl compatible regular expressions (and I know and like PHP and Perl)
kestasjk (95 DMod(P))
15 Oct 10 UTC
@Alderian I usually do that in large blocks of code where there's lots of space, I think it looks neat when you've got lots of comments etc, but for smaller stuff I usually put it on the same line. I like either way
kestasjk (95 DMod(P))
15 Oct 10 UTC
(No comment on whether ++foo or foo++ is quicker though, I think with modern processors it's probably not much of an issue but I may be wrong)
Alderian (2425 D(S))
15 Oct 10 UTC
True. And maybe it gets optimized out in any case when it detects you aren't doing anything with the return value.
Draugnar (0 DX)
15 Oct 10 UTC
foo++ v. ++foo

foo++ returns value then increments existing variable
++foo increments existing variable then return value

Same number of operations, just an issue of order. Maybe in the guts, it has to set aside the original value for the return, but this is a single move operation that takes nanoseconds on a modern processor.

But it has been a few years since I worked in C and pointers are no longer my forte (never really were). Wanna explain why it is right and what the prupose of the last loop on available is for?
Alderian (2425 D(S))
15 Oct 10 UTC
Sure. Keep in mind that these variables are defined outside the for loops so exist after the for loop. current and available are both initialized to the start of the array. (I have &array but should really be &array[0], sorry I was in a hurry.)

The first for loop takes increments the current pointer from one end of the array to the other. But the available pointer is only incremented when a non-zero value is found, so it may not have made it to the end of the array

The second for loop just picks up where the first one ended with regard to the available pointer and increments it to the end of the array.

So let's say you have 0, 1, 0, 1. After the first for loop, the array now looks like 1, 1, 0, 1 and available is pointing at the third entry. The second for loop clears the 3rd and 4th entries.
Alderian (2425 D(S))
15 Oct 10 UTC
Again, I was just copying Kesta's code and changing it to use pointers instead of array indexes. Really this could be further simplified...

short array[1000];
short * available;
short * current;
short * end = &array[0] + countof(array);

srand(13);
for (current = &array[0]; current < end; ++current)
{
__*current = rand() % 2;
}

for (current = available = &array[0] ; current < end; ++current)
{
__if (*current != 0)
__{
____*available = *current;
____*current = 0;
____++available;
__}
}
Alderian (2425 D(S))
15 Oct 10 UTC
And I suppose &array[0] is redundant and I can just use array. For some reason I always try using &array which the compiler errors out on and then I add [0] instead of removing the &.
Draugnar (0 DX)
15 Oct 10 UTC
So lets say you have 0, 1, 3, 9, 0, 4

Following your code you get 1,3,9,4,0,4 then the second loop clears it. Not bad. I like it and it is very efficient, even more so than mine I think and not just because of the pointers, which not every language takes advantage of.
philcore (317 D(S))
15 Oct 10 UTC
regarding pre and post incrementers: I think the biggest difference is when you're implementing your own types and overloading their operators. The implementation for post requires an additional copy of your class which will be returned, while you then increment your instance. pre inc is just incrementing your instance and returning it - no additional copies. So it's preferable to use the pre unless you specifically WANT the post (I think I've needed that 6 times in 20 years). if you're just looking to increment it though, then pre is more efficient.
alamothe (3367 D(B))
15 Oct 10 UTC
fuck off!!
Draugnar (0 DX)
15 Oct 10 UTC
@Alamothe - What's your problem, man?
Alderian (2425 D(S))
15 Oct 10 UTC
I'm guessing that Z knows that alamothe hates it when programmers talk about different ways to program things so posted this post just to piss alamothe off. If so, mission succeeded!

But I suppose I could be wrong. :)
bigworm (390 D)
15 Oct 10 UTC
> not just because of the pointers, which not every language takes advantage of.

Almost every language has pointers, some of them just call them references. Understanding pointers is integral to understanding how to program.
philcore (317 D(S))
15 Oct 10 UTC
alamothe's last name must be Massingill

Page 3 of 4
FirstPreviousNextLast
 

93 replies
curtis (8870 D)
15 Oct 10 UTC
gunboat live
7 replies
Open
Dpddouglass (908 D)
14 Oct 10 UTC
New public game, 150 pts, 3 day turns
http://webdiplomacy.net/board.php?gameID=39976
1 reply
Open
President Eden (2750 D)
15 Oct 10 UTC
HEY JACKASS, VOTE DRAW
In case you missed it the first couple times. You cannot advance past the stalemate line, you're not doing anything to try, so stop dragging the game out and vote draw. For the bystanders: http://webdiplomacy.net/board.php?gameID=40053#gamePanel
20 replies
Open
Stenrosen (1110 D)
15 Oct 10 UTC
Bug?
In this game (http://webdiplomacy.net/board.php?gameID=39585) Oz retreated a fleet from Dumont dUrville to Vostok (in spring 2003, retreats). It seems like a bug to me, but please enlighten me...
3 replies
Open
penguinflying (111 D)
15 Oct 10 UTC
Signaling in gunboat games?
Can someone please explain any standard conventions that exist for signaling in gunboat games? Like...I think ordering a support hold to someone else's unit must mean something, but I'm not sure what.
8 replies
Open
Fear Rua (133 D)
14 Oct 10 UTC
Moves saved or ready
Hi, another newby question. If you have moves saved but not ready when the movement phase ends, will these moves be implemented, or will you be treated as having not entered any moves?

Is there any help page that explains how the webdiplomacy interface works, as opposed to the rules of the game? All I can find are the FAQ, the introduction, and the rulebook, none of which provide many details of this.
6 replies
Open
peterwiggin (15158 D)
15 Oct 10 UTC
linux help?
In light of recent tradition . . .
6 replies
Open
Thucydides (864 D(B))
15 Oct 10 UTC
Remember my diplomacy club idea?
I just wanted you blokes to know that it's actually happening, I've been approved.
5 replies
Open
Iceray0 (266 D(B))
15 Oct 10 UTC
Fuck yea
I haven't played a game in forever and i've gone from barely breaking the top 40% to being in the top 30%
I am a badass. It's not due to new members, it's 100% badassness.
3 replies
Open
eaglesfan642 (0 DX)
12 Oct 10 UTC
Please join
Please join http://webdiplomacy.net/board.php?gameID=39922
75 bet
World diplomacy
2 replies
Open
Lando Calrissian (100 D(S))
14 Oct 10 UTC
Live Games Tonight
Is there any interest in a high-ish pot live gunboat tonight? I'd set up a game and make it password protected. I'm thinking maybe 50 yen buy-in. Reply or message if this interests you.
1 reply
Open
mapleleaf (0 DX)
09 Oct 10 UTC
read ZEITOUN...
...if you haven't read it already. It's by Dave Eggers.
2 replies
Open
Tom Bombadil (4023 D(G))
14 Oct 10 UTC
New 101d WTA anon game
36 hour phases. All press. Join up!
2 replies
Open
hopsyturvy (521 D)
14 Oct 10 UTC
Server errors
for info, *not* a moaning thread.
5 replies
Open
no pants (100 D)
13 Oct 10 UTC
StP bug?
see post
8 replies
Open
Thucydides (864 D(B))
12 Oct 10 UTC
Personal Philosophy
A this risk of appearing egotistical... I would like to share with you guys something I wrote.
33 replies
Open
Conservative Man (100 D)
13 Oct 10 UTC
What did I do wrong on this math problem?
I'm trying to find the equation of a parabola by using 3 of its points. The points are (1,6) (3,26) and (-2,21). I'm trying to find the form y=ax^2+bx+c. I worked out a to be 2.5, but the book says it is 3. You can find my work inside.
45 replies
Open
stratagos (3269 D(S))
14 Oct 10 UTC
ARARUGH!
I HATE MISORDERS!

That is all. The EOG comments on this one are going to be fucking *Fascinating* to read, when everyone asks WTF I was thinking
1 reply
Open
obiwanobiwan (248 D)
10 Oct 10 UTC
I am REALLY Losing Faith...
I am rapidly lost my faith in democracy--living through it the last decade plus, from the last couple disgraceful years of Clinton to Bush II's Regime to Obama's Bust (AND Ahnuld and our near-last education, jobs, etc. in CAL) right here in my home state, I now think maybe Plato was right...and Hobbes...I'm not advocating for "1984" or an Emperor or Reich here, but...well, all this bickering and I see FAR more hurt and waste than good...discuss?
126 replies
Open
stratagos (3269 D(S))
14 Oct 10 UTC
Whoo hoo, you go Chile!
You guys have one hell of a country - I can't see us in the states being able to pull off what you guys did anywhere *near* as smoothly. You should be *damn* proud of the bar you've set for the rest of us screwed up, selfish nations when it comes to caring about our citizens.
18 replies
Open
obiwanobiwan (248 D)
10 Oct 10 UTC
Give The Title Of Your Autobiography
Simple enough--one sentence, give a fitting title of your autobiography if you were to write it today.
57 replies
Open
jman777 (407 D)
13 Oct 10 UTC
Who Took The PSAT Today?
Did anyone here take the PSAT today? I did and had form W. It wasn't that bad except for the fact that I messed up some formulas.
8 replies
Open
baumhaeuer (245 D)
25 Aug 10 UTC
Experament
Details inside.
201 replies
Open
omgwhathappened (0 D)
14 Oct 10 UTC
Spring 1903
gameID=39477

need a replacement austria. has 6 centers, and no one is currently aggressive. italy, germany and england are fighting france, and austria is not under fire from either russia or turkey. good set up, and we'd like a replacement for the guy who JUST left.
2 replies
Open
Conservative Man (100 D)
09 Oct 10 UTC
Am I crazy?
See inside
75 replies
Open
Page 666 of 1419
FirstPreviousNextLast
Back to top