• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 14:24
CEST 20:24
KST 03:24
  • Home
  • Forum
  • Calendar
  • Streams
  • Liquipedia
  • Features
  • Store
  • EPT
  • TL+
  • StarCraft 2
  • Brood War
  • Smash
  • Heroes
  • Counter-Strike
  • Overwatch
  • Liquibet
  • Fantasy StarCraft
  • TLPD
  • StarCraft 2
  • Brood War
  • Blogs
Forum Sidebar
Events/Features
News
Featured News
Serral wins HomeStory Cup 2914Serral wins Maestros of the Game 243ByuL, and the Limitations of Standard Play3Team Liquid Map Contest #22: Results and Winners7Code S Season 2 (2026): RO4 and Finals Preview12
Community News
Reynor: GSL Loss Wasn't About Preparation Format12[IPSL] Spring 2026 Grand Finals - This Weekend!5Weekly Cups (July 6 - 12): Protoss strike back12BSL Season 22 Full Overview & Conclusion8BSL Season 22 Full Overview & Conclusion8
StarCraft 2
General
5.0.16 patch for SC2 goes live (8 worker start) Is the larve respawn broken? BGE Stara Zagora to be held again in June 2025 Weekly Cups (July 6 - 12): Protoss strike back Serral wins HomeStory Cup 29
Tourneys
WardiTV Summer Cup 2026 GSL CK #5 Race War RSL Revival: Season 6 - Qualifiers and Main Event HomeStory Cup 29 Vespene Cup #1 — $300+ USD, July 10
Strategy
[G] Having the right mentality to improve
Custom Maps
New Map Maker - Looking for Advice - Love or Hate Work In Progress Melee Maps [D]RTS in all its shapes and glory <3
External Content
The PondCast: SC2 News & Results Mutation # 534 Burning Evacuation Mutation # 533 Die Together Mutation # 532 Nuclear Family
Brood War
General
Recommended FPV games (post-KeSPA) Pros Debate: Zerg Unfairly Nerfed? (ASL S22 map) BGH Auto Balance -> http://bghmmr.eu/ Etiquete rules in Asl? screpdb: new Starcraft reporting tool
Tourneys
[IPSL] Spring 2026 Grand Finals - This Weekend! Escore Tournament - Season 3 [Megathread] Daily Proleagues [ASL22] Wildcard Qualifier
Strategy
Fighting Spirit mining rates Simple Questions, Simple Answers Creating a full chart of Zerg builds Relatively freeroll strategies
Other Games
General Games
Nintendo Switch Thread General RTS Discussion Thread Path of Exile Stormgate/Frost Giant Megathread Summer Games Done Quick 2026!
Dota 2
Looking for a Dota Mentor Official 'what is Dota anymore' discussion
League of Legends
Heroes of the Storm
Simple Questions, Simple Answers Heroes of the Storm 2.0
Hearthstone
Deck construction bug
TL Mafia
TL Mafia Power Rank NeO.D_StephenKing vs This Guy From 1 Million Dance TL Mafia Community Thread Vanilla Mini Mafia
Community
General
US Politics Mega-thread Russo-Ukrainian War Thread UK Politics Mega-thread YouTube Thread Canadian Politics Mega-thread
Fan Clubs
The IdrA Fan Club The HerO Fan Club!
Media & Entertainment
Anime Discussion Thread [Req][Books] Good Fantasy/SciFi books Movie Discussion! Series you have seen recently...
Sports
2024 - 2026 Football Thread MLB/Baseball 2023 McBoner: A hockey love story Tennis[sport] Formula 1 Discussion
World Cup 2022
Tech Support
Simple Questions Simple Answers FPS when play League Of Legend on laptop How to clean a TTe Thermaltake keyboard?
TL Community
Northern Ireland Global Starcraft The Automated Ban List
Blogs
Poker (part 2)
Nebuchad
The Experiences We Want and …
TrAiDoS
An Exploration of th…
waywardstrategy
Gauntlet SC2: A Retrospectiv…
Ctone23
ramps on octagon
StaticNine
Funny Nicknames
LUCKY_NOOB
Evil Gacha Games and the…
ffswowsucks
Customize Sidebar...

Website Feedback

Closed Threads



Active: 5512 users

The Big Programming Thread - Page 209

Forum Index > General Forum
Post a Reply
Prev 1 207 208 209 210 211 1032 Next
Thread Rules
1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution.
2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20)
3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible.
4. Use [code] tags to format code blocks.
mustache
Profile Joined April 2010
Switzerland309 Posts
December 05 2012 08:45 GMT
#4161
I'm programming a small snake game in C that runs in the console window. right now it clears and redraws the entire screen every time the snake moves 1 increment. this make the bottom of the screen start flickering because the redraw at the bottom takes longer than the top.

my question is if there is a way to go to a specific line in the console window, delete that line, and redraw it. that way i could check if something changed and update only that line.

using windows and visual basic
Sub40APM
Profile Joined August 2010
6336 Posts
December 05 2012 09:25 GMT
#4162
On December 04 2012 06:48 Blisse wrote:

For example, if you call lower() on a string, then you check if the string has any uppercase letters. It even sounds redundant, no? as how can a lower cased string have uppercase letters anyways?

I agree with most of your post but must come to his defense. If you look back to his code, while he converts the input string into lower and does stuff to it, his check on Uppercase applies to the original input string, whatever it may be.
Arnstein
Profile Blog Joined May 2010
Norway3381 Posts
December 05 2012 10:33 GMT
#4163
Anyone know where I can find good exercises for double lists and matrices in Python?
rsol in response to the dragoon voice being heard in SCII: dragoon ai reaches new lows: wanders into wrong game
KaiserJohan
Profile Joined May 2010
Sweden1808 Posts
Last Edited: 2012-12-05 10:53:57
December 05 2012 10:47 GMT
#4164
I'm heavy into C++ and .NET but I need to learn some PHP+mySQL. Are there any good advanced tutorial sites out there? As in, they don't have to explain all the programming basics, just the language itself and the environment to work in. I have never developed in a web language so I'm new in that specific area.

Also what good free IDEs are there for php?
England will fight to the last American
AmericanUmlaut
Profile Blog Joined November 2010
Germany2596 Posts
December 05 2012 11:28 GMT
#4165
On December 05 2012 19:47 KaiserJohan wrote:
Also what good free IDEs are there for php?

I use NetBeans for PHP and it works very well.
The frumious Bandersnatch
KaiserJohan
Profile Joined May 2010
Sweden1808 Posts
December 05 2012 11:36 GMT
#4166
What about the eclipse PHP plugins?
England will fight to the last American
Kambing
Profile Joined May 2010
United States1176 Posts
Last Edited: 2012-12-05 16:05:15
December 05 2012 14:17 GMT
#4167
On December 05 2012 17:41 ghrur wrote:
Hi guys,

So next semester, I will be learning Python as part of a Comp Sci class I'll be taking. At the end of the class, we'll have to make a project primarily in Python. I've heard about this from my friends who're taking it now, so I've started contemplating the project. One of the thoughts I had was making an AI of sorts to play BW. It'd probably work through BWAPI. The problem is, a lot of my friends also say Python is too slow to be able to make the calculations for a game AI.

Anyway, I'd just like some opinions on if it'd be possible to build a BW AI-bot in python.

Thanks!


It's perfectly reasonable; you aren't going to be building anything crazy performance-demanding.

The only catch is that the BWAPI library is written in C++ so you would need to understand how to interop with C++ code from Python. Luckily, someone's already written Python bindings against BWAPI, so you don't even need to worry about that:

http://code.google.com/p/bwapi/
http://code.google.com/p/pybw/
Blisse
Profile Blog Joined July 2010
Canada3710 Posts
December 05 2012 14:28 GMT
#4168
On December 05 2012 17:45 mustache wrote:
I'm programming a small snake game in C that runs in the console window. right now it clears and redraws the entire screen every time the snake moves 1 increment. this make the bottom of the screen start flickering because the redraw at the bottom takes longer than the top.

my question is if there is a way to go to a specific line in the console window, delete that line, and redraw it. that way i could check if something changed and update only that line.

using windows and visual basic


I came across the same problem before. I knew this ability existed, because if you've used a lot of terminal installers, they often have a static download bar. However, I never found out how to do this.

I would appreciate an answer to this problem as well, even though I've moved on.



On December 05 2012 18:25 Sub40APM wrote:
Show nested quote +
On December 04 2012 06:48 Blisse wrote:

For example, if you call lower() on a string, then you check if the string has any uppercase letters. It even sounds redundant, no? as how can a lower cased string have uppercase letters anyways?

I agree with most of your post but must come to his defense. If you look back to his code, while he converts the input string into lower and does stuff to it, his check on Uppercase applies to the original input string, whatever it may be.


Ooops. XD Strange that I missed that, though that would be another sample of redundancy, for this case.
Actually, now I'm deciding if it was wrong to get the Pig Latin of the lowercased word, though I'm not sure how abbreviations and proper nouns should be handled, because the words that would be created wouldn't be real words (though it's never a real word anyways).
There is no one like you in the universe.
CecilSunkure
Profile Blog Joined May 2010
United States2829 Posts
Last Edited: 2012-12-05 16:47:29
December 05 2012 16:46 GMT
#4169
On December 05 2012 17:41 ghrur wrote:
Hi guys,

So next semester, I will be learning Python as part of a Comp Sci class I'll be taking. At the end of the class, we'll have to make a project primarily in Python. I've heard about this from my friends who're taking it now, so I've started contemplating the project. One of the thoughts I had was making an AI of sorts to play BW. It'd probably work through BWAPI. The problem is, a lot of my friends also say Python is too slow to be able to make the calculations for a game AI.

Anyway, I'd just like some opinions on if it'd be possible to build a BW AI-bot in python.

Thanks!

A lot of your friends say Python is too slow for AI calculations? Sigh... A lot of your friends like to make assumptions without testing them. Python is perfectly fine for scripting AI. Your friends don't know what they're talking about.

On December 05 2012 17:45 mustache wrote:
I'm programming a small snake game in C that runs in the console window. right now it clears and redraws the entire screen every time the snake moves 1 increment. this make the bottom of the screen start flickering because the redraw at the bottom takes longer than the top.

my question is if there is a way to go to a specific line in the console window, delete that line, and redraw it. that way i could check if something changed and update only that line.

using windows and visual basic

That's weird, are you multi-threading at all? That sounds like screen tearing where you're calling WriteConsoleOutput too quickly. Are you at least double buffering? Here's a couple links, which should be way more than enough information for you to fix this:
http://cecilsunkure.blogspot.com/2011/11/windows-console-game-setting-up-window.html
http://cecilsunkure.blogspot.com/2012/07/windows-console-game-ascii-engine.html
mustache
Profile Joined April 2010
Switzerland309 Posts
Last Edited: 2012-12-05 18:26:41
December 05 2012 18:24 GMT
#4170
+ Show Spoiler +

void Print_Field()
{
int i;
int h;
system("cls"); // clears old screen
printf("points: %d\n", points); // displays points in first console line
for(i=0, h=1; i<AREA; i++) // prints gamefield, until the array with size AREA is completely printed
{
if(i == h*WIDTH) // array is 1 dimensional ; program skips to a new line every time WIDTH has been reached
{
printf("\n");
h=h+1;
}
printf("%c", field[i].sprite); // chooses what character is printed

}
}


so im just cycling through my array and printing the values that are in that. but because the redrawing isnt fast enough the screen flickers(i assume)

I've just started out programming in general so im not sure what multi threading or double buffering is.(so im probably not using it)

ill check out the links in detail, but i'd like to program the game from start to finish by my self, to get more familiar with how things work.

EDIT: i noticed in my first post i wrote im using visual basic. I meant visual studio c++, and im coding in C. ouch
Bigpet
Profile Joined July 2010
Germany533 Posts
December 05 2012 18:30 GMT
#4171
On December 06 2012 03:24 mustache wrote:
+ Show Spoiler +

void Print_Field()
{
int i;
int h;
system("cls"); // clears old screen
printf("points: %d\n", points); // displays points in first console line
for(i=0, h=1; i<AREA; i++) // prints gamefield, until the array with size AREA is completely printed
{
if(i == h*WIDTH) // array is 1 dimensional ; program skips to a new line every time WIDTH has been reached
{
printf("\n");
h=h+1;
}
printf("%c", field[i].sprite); // chooses what character is printed

}
}


so im just cycling through my array and printing the values that are in that. but because the redrawing isnt fast enough the screen flickers(i assume)

I've just started out programming in general so im not sure what multi threading or double buffering is.(so im probably not using it)

ill check out the links in detail, but i'd like to program the game from start to finish by my self, to get more familiar with how things work.

EDIT: i noticed in my first post i wrote im using visual basic. I meant visual studio c++, and im coding in C. ouch


I don't know about the performance characteristics of system("cls") but you shouldn't printf() every single charater. You flush way too often that way. I'd advise you sprintf() a whole frame and just call printf() once you constructed the whole frame.
I'm NOT the caster with a similar nick
Deleted User 101379
Profile Blog Joined August 2010
4849 Posts
December 05 2012 18:34 GMT
#4172
On December 06 2012 03:24 mustache wrote:
+ Show Spoiler +

void Print_Field()
{
int i;
int h;
system("cls"); // clears old screen
printf("points: %d\n", points); // displays points in first console line
for(i=0, h=1; i<AREA; i++) // prints gamefield, until the array with size AREA is completely printed
{
if(i == h*WIDTH) // array is 1 dimensional ; program skips to a new line every time WIDTH has been reached
{
printf("\n");
h=h+1;
}
printf("%c", field[i].sprite); // chooses what character is printed

}
}


so im just cycling through my array and printing the values that are in that. but because the redrawing isnt fast enough the screen flickers(i assume)

I've just started out programming in general so im not sure what multi threading or double buffering is.(so im probably not using it)

ill check out the links in detail, but i'd like to program the game from start to finish by my self, to get more familiar with how things work.

EDIT: i noticed in my first post i wrote im using visual basic. I meant visual studio c++, and im coding in C. ouch


It's not possible in default C as far as i remember, though there are libraries for that.
From a quick google, http://www.projectpluto.com/win32a.htm should work. I haven't tried it though since most of my C development was under linux where we had ncurses (which is not available for windows).
Blisse
Profile Blog Joined July 2010
Canada3710 Posts
December 05 2012 18:37 GMT
#4173
On December 06 2012 03:24 mustache wrote:
+ Show Spoiler +

void Print_Field()
{
int i;
int h;
system("cls"); // clears old screen
printf("points: %d\n", points); // displays points in first console line
for(i=0, h=1; i<AREA; i++) // prints gamefield, until the array with size AREA is completely printed
{
if(i == h*WIDTH) // array is 1 dimensional ; program skips to a new line every time WIDTH has been reached
{
printf("\n");
h=h+1;
}
printf("%c", field[i].sprite); // chooses what character is printed

}
}


so im just cycling through my array and printing the values that are in that. but because the redrawing isnt fast enough the screen flickers(i assume)

I've just started out programming in general so im not sure what multi threading or double buffering is.(so im probably not using it)

ill check out the links in detail, but i'd like to program the game from start to finish by my self, to get more familiar with how things work.

EDIT: i noticed in my first post i wrote im using visual basic. I meant visual studio c++, and im coding in C. ouch


Could you try building the array as a giant string, and then calling printf once on that entire string? That should solve it.


@Cecil, I think he's writing a literal basic Console program, not a WIN32 application that interfaces with the Console. XD (even though it's kinda a subset of the other)
There is no one like you in the universe.
RoyGBiv_13
Profile Blog Joined August 2010
United States1275 Posts
Last Edited: 2012-12-05 18:51:27
December 05 2012 18:50 GMT
#4174
On December 06 2012 03:37 Blisse wrote:
Show nested quote +
On December 06 2012 03:24 mustache wrote:
+ Show Spoiler +

void Print_Field()
{
int i;
int h;
system("cls"); // clears old screen
printf("points: %d\n", points); // displays points in first console line
for(i=0, h=1; i<AREA; i++) // prints gamefield, until the array with size AREA is completely printed
{
if(i == h*WIDTH) // array is 1 dimensional ; program skips to a new line every time WIDTH has been reached
{
printf("\n");
h=h+1;
}
printf("%c", field[i].sprite); // chooses what character is printed

}
}


so im just cycling through my array and printing the values that are in that. but because the redrawing isnt fast enough the screen flickers(i assume)

I've just started out programming in general so im not sure what multi threading or double buffering is.(so im probably not using it)

ill check out the links in detail, but i'd like to program the game from start to finish by my self, to get more familiar with how things work.

EDIT: i noticed in my first post i wrote im using visual basic. I meant visual studio c++, and im coding in C. ouch


Could you try building the array as a giant string, and then calling printf once on that entire string? That should solve it.


@Cecil, I think he's writing a literal basic Console program, not a WIN32 application that interfaces with the Console. XD (even though it's kinda a subset of the other)


Yep, turns out this is one of those things Windows sucks at. This program would run as intended on a Unix box, because of how POSIX streams work. In any case, probably best practice to build your string first, then print it. It will make the code a bit more readable.

Also, sorry that you have to deal with windows command line :/


Any sufficiently advanced technology is indistinguishable from magic
CecilSunkure
Profile Blog Joined May 2010
United States2829 Posts
December 05 2012 18:51 GMT
#4175
On December 06 2012 03:37 Blisse wrote:
Show nested quote +
On December 06 2012 03:24 mustache wrote:
+ Show Spoiler +

void Print_Field()
{
int i;
int h;
system("cls"); // clears old screen
printf("points: %d\n", points); // displays points in first console line
for(i=0, h=1; i<AREA; i++) // prints gamefield, until the array with size AREA is completely printed
{
if(i == h*WIDTH) // array is 1 dimensional ; program skips to a new line every time WIDTH has been reached
{
printf("\n");
h=h+1;
}
printf("%c", field[i].sprite); // chooses what character is printed

}
}


so im just cycling through my array and printing the values that are in that. but because the redrawing isnt fast enough the screen flickers(i assume)

I've just started out programming in general so im not sure what multi threading or double buffering is.(so im probably not using it)

ill check out the links in detail, but i'd like to program the game from start to finish by my self, to get more familiar with how things work.

EDIT: i noticed in my first post i wrote im using visual basic. I meant visual studio c++, and im coding in C. ouch


Could you try building the array as a giant string, and then calling printf once on that entire string? That should solve it.


@Cecil, I think he's writing a literal basic Console program, not a WIN32 application that interfaces with the Console. XD (even though it's kinda a subset of the other)


Oh I see, haha. Yeah just use a single printf call. The screen might "flicker" a little when the console scrolls. You can change the height in characters of the console so that it cannot scroll, if you wanted to.
Recognizable
Profile Blog Joined December 2011
Netherlands1552 Posts
Last Edited: 2012-12-05 18:53:05
December 05 2012 18:52 GMT
#4176
Could somebody explain to me whilst keeping terminology to a minimum what Indendation(Python) actually does. I keep coding and doing stuff but this is something I keep wondering about. My guess is that it separates things.
CecilSunkure
Profile Blog Joined May 2010
United States2829 Posts
Last Edited: 2012-12-05 18:55:33
December 05 2012 18:55 GMT
#4177
On December 06 2012 03:52 Recognizable wrote:
Could somebody explain to me whilst keeping terminology to a minimum what Indendation(Python) actually does. I keep coding and doing stuff but this is something I keep wondering about. My guess is that it separates things.

It creates a new scope every time you indent. The scope closes when the indent is de-indented.
mustache
Profile Joined April 2010
Switzerland309 Posts
December 05 2012 18:59 GMT
#4178
Ok thanks, ill try using a single string, though on my first try the game start crashing :D ill have to give it another go


btw here the code if anyone's interested, and wants to see the flickering.
+ Show Spoiler +
#include <stdio.h>
#include <conio.h>
#include <Windows.h>
#include <time.h>

/**************************************************************************************************************/
#define HEIGHT (24)
#define WIDTH (50)
#define AREA (HEIGHT*WIDTH)
#define MAX_LENGTH (40)
//#define LENGTH (30)
#define RIGHT ('d')
#define LEFT ('a')
#define UP ('w')
#define DOWN ('s')


/**************************************************************************************************************/
struct position // structure prototype for positions in array
{
int x;
int y;
char sprite;
};

struct position field[AREA]; // gamefield array
struct position snake[MAX_LENGTH]; // snake body array
struct position snake_temp[MAX_LENGTH]; // temp snake array copy
struct position fruit;
char input = RIGHT;
int SPEED = 5;
int points = 0;
int LENGTH = 1;
char buffer[AREA+1];
/**************************************************************************************************************/
int Game_Menu();
int Sub_Menu();
void Field_Set();
void Print_Field();
int Snake_Set();
void Snake_Input();
void Snake_Init();
void Menu();
void Fruit_Gen();
void Fruit_Set();
/**************************************************************************************************************/

int main()
{
int game_loop = 1;
int main_loop = 1;
srand(time(NULL));

while(main_loop ==1)
{
Game_Menu();

game_loop = 1;
while (game_loop == 1)
{
Snake_Input();
Field_Set();
Fruit_Set();
game_loop = Snake_Set();
Print_Field();
}
}
return 0;
}

int Game_Menu()
{
int menu = 1;
int game_loop;
char menu_input = 'o';


while( menu == 1)
{
Menu();
menu_input = getch();
menu = Sub_Menu(menu_input);
}

system("cls");
return 0;
}
void Menu()
{
system("cls");
printf("*******************************************************************************\n");
printf("* ***** * * ***** * * **** *\n");
printf("* * ** * * * * * * *\n");
printf("* ***** * * * ***** * ** *\n");
printf("* * * ** * * * * * *\n");
printf("* ***** * * * * * * **** *\n");
printf("* *\n");
printf("* *\n");
printf("* *\n");
printf("* *\n");
printf("* *\n");
printf("* SET SPEED OPTIONS[s] SET OBSTACLE OPTIONS[o] *\n");
printf("* *\n");
printf("* *\n");
printf("* *\n");
printf("* *\n");
printf("* *\n");
printf("* *\n");
printf("* START GAME[y] *\n");
printf("* *\n");
printf("* *\n");
printf("* *\n");
printf("* *\n");
printf("* exit[x] *\n");
printf("*******************************************************************************\n");
}
int Sub_Menu(char menu_input)
{
int output = 1;
char set_char = 'z';

switch(menu_input)
{
case 's':
system("cls");
printf("*******************************************************************************\n");
printf("* ***** * * ***** * * **** *\n");
printf("* * ** * * * * * * *\n");
printf("* ***** * * * ***** * ** *\n");
printf("* * * ** * * * * * *\n");
printf("* ***** * * * * * * **** *\n");
printf("* DIFFICULTY SETTINGS *\n");
printf("* *\n");
printf("* *\n");
printf("* *\n");
printf("* *\n");
printf("* HARD[h] EASY[e] *\n");
printf("* *\n");
printf("* *\n");
printf("* *\n");
printf("* *\n");
printf("* *\n");
printf("* *\n");
printf("* MIDDLE[m] *\n");
printf("* *\n");
printf("* *\n");
printf("* *\n");
printf("* *\n");
printf("* exit[x] *\n");
printf("*******************************************************************************\n");

while(set_char != 'm' && set_char != 'e' && set_char != 'h')
{
set_char = getch();
}
switch(set_char)
{
case 'e':
SPEED = 100;
break;
case 'm':
SPEED = 5;
break;
case 'h':
SPEED = 0;
}
break;
case 'o':
printf("you are in obstacle menu");
break;
case 'y':
output = 0;
Snake_Init();
break;
case 'x':
printf("you exited the game");
break;
}

return output;
}

void Field_Set()
{
int i,h;// counter variable




for(i = 0, h=0; i< AREA;i++)// writes x and y coordinates into gamefield array
{

field[i].x = i%WIDTH;
field[i].y = i/WIDTH;
}


for(i = 0; i< AREA; i++)// writes boundarys into gamefield
{
if(field[i].x == 0 || field[i].x == (WIDTH-1) || field[i].y == 0 || field[i].y == (HEIGHT-1))
{
field[i].sprite = '*'; // boundary
}
else
{
field[i].sprite = ' '; // empty space
}
}
}

void Print_Field()
{
int i;
int h;
system("cls");
printf("points: %d\n", points);
for(i=0, h=1; i<AREA; i++) // prints gamefield
{
if(i == h*WIDTH)
{
printf("\n");

h=h+1;
}
printf("%c", field[i].sprite);

}


}

int Snake_Set()
{
int game_loop = 1;
int i;

for(i=0;i<LENGTH;i++)
{
if(field[snake[i].x + snake[i].y*WIDTH].sprite == '*' ||field[snake[i].x + snake[i].y*WIDTH].sprite == 'X')
{
Beep(500,500);
game_loop = 0;
}
else if(field[snake[i].x + snake[i].y*WIDTH].sprite == 'O')
{
points = points + 10;
if(LENGTH < MAX_LENGTH-1)
{
LENGTH = LENGTH +1;
}
Fruit_Gen();
Beep(500,30);
Beep(400,100);
}
else
{
field[snake[i].x+ snake[i].y*WIDTH].sprite = '*';
}
}
return game_loop;
}

void Snake_Input() // DONT FORGET TO SET THE DIRECTION TO AN INITIAL VALUE
{
int i;
int temp_input;


for(i=0; i<1; i++)
{
if(kbhit() == 1)
{
temp_input = getch();

if(temp_input == RIGHT || temp_input == LEFT || temp_input == UP ||temp_input == DOWN)
{
input = temp_input;
}
}
else
{
Sleep(SPEED);
}
}
for(i=0; i<LENGTH; i++) // copies snake into a temp snake array, and increase the positions
{
snake_temp[i].x = snake[i].x;
snake_temp[i].y = snake[i].y;
}

for(i=0;i<LENGTH;i++)
{
snake[i+1].x = snake_temp[i].x;
snake[i+1].y = snake_temp[i].y;
}


switch(input)
{
case RIGHT:
snake[0].x = snake[0].x + 1;
break;
case LEFT:
snake[0].x = snake[0].x - 1;
break;
case UP:
snake[0].y = snake[0].y - 1;
break;
case DOWN:
snake[0].y = snake[0].y + 1;
break;
}
}

void Snake_Init()
{
int i;
Fruit_Gen();
points = 0;
LENGTH = 1;
for(i = 0; i<MAX_LENGTH;i++)
{
snake[i].x = WIDTH/2-i;
snake[i].y = HEIGHT/2;
}
}

void Fruit_Gen()
{
int random_x;
int random_y;
int fruit_loop = 1;

while(fruit_loop == 1)
{
random_x = rand()%(WIDTH/2+1);
random_y = rand()%(HEIGHT/2+1);
if(random_x != 0 && random_x != WIDTH && random_y != 0 && random_y != HEIGHT)
{
fruit_loop = 0;
fruit.x = random_x;
fruit.y = random_y;
}
}
}

void Fruit_Set()
{
field[fruit.x+ fruit.y*WIDTH].sprite = 'O';
}
Recognizable
Profile Blog Joined December 2011
Netherlands1552 Posts
Last Edited: 2012-12-05 19:06:29
December 05 2012 19:06 GMT
#4179
I had to search for what scope is but I guess I understand it a bit better now. Why is this important? Why doesn't the computer understand what you are doing when you aren't indenting?

def f(a,b):
c = a + b
c = g(c) + X
d = c * c + a
return d * b


Am I right in saying that this works because return is in the same scope as C,D and so it can do something with these variables. If return wasn't indented it wouldn't be able to do that because it wasn't in the same scope and therefore can't do anything with those variables?
CecilSunkure
Profile Blog Joined May 2010
United States2829 Posts
December 05 2012 19:10 GMT
#4180
On December 06 2012 04:06 Recognizable wrote:
I had to search for what scope is but I guess I understand it a bit better now. Why is this important? Why doesn't the computer understand what you are doing when you aren't indenting?

def f(a,b):
c = a + b
c = g(c) + X
d = c * c + a
return d * b


Am I right in saying that this works because return is in the same scope as C,D and so it can do something with these variables. If return wasn't indented it wouldn't be able to do that because it wasn't in the same scope and therefore can't do anything with those variables?

Yeah that's right. When you make something within a scope, things outside of that scope cannot access the variable. It's not about the computer "knowing what you are doing", the Python interpreter is just following rules the creator laid out. Scoping is a good thing.

If there was no scoping (or another way to say this is if there were only the global scope) then you could only have one name to one identifier. This gets annoying when you want to reuse an identifier.


for i in range( 0, 10 ):
print( i )

for x in range( 0, 10 ):
print( x )


You can see here I've already used two different identifiers, x and i. Luckily those two variables are within the scope of the for loops, otherwise I'd have to use a different variable name for each loop.
Prev 1 207 208 209 210 211 1032 Next
Please log in or register to reply.
Live Events Refresh
OSC
17:00
Mid Season Playoffs
MaxPax vs Solar
ByuN vs Cure
Shameless vs Lambo
SKillous vs Cham
Percival vs Harstem
ShoWTimE vs Krystianer
SteadfastSC240
Liquipedia
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
LamboSC2 378
mouzHeroMarine 305
SteadfastSC 240
UpATreeSC 125
BRAT_OK 73
mouzStarbuck 30
EmSc Tv 15
elazer 15
MindelVK 8
JuggernautJason5
StarCraft: Brood War
Calm 5620
Mong 175
Dewaltoss 113
910 32
scan(afreeca) 31
Killer 31
Dota 2
qojqva2075
Trikslyr60
League of Legends
KnowMe77
Counter-Strike
fl0m1941
x6flipin463
allub298
kRYSTAL_165
Heroes of the Storm
Liquid`Hasu200
Other Games
singsing2086
ceh91369
Liquid`RaSZi986
B2W.Neo479
XaKoH 167
C9.Mang0100
RuFF_SC215
Organizations
Other Games
gamesdonequick2363
StarCraft 2
TaKeTV580
EmSc Tv 15
EmSc2Tv 15
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
[ Show 20 non-featured ]
StarCraft 2
• StrangeGG 62
• Hupsaiya 62
• Reevou 7
• Kozan
• Migwel
• AfreecaTV YouTube
• sooper7s
• intothetv
• IndyKCrew
• LaughNgamezSOOP
StarCraft: Brood War
• blackmanpl 25
• 80smullet 11
• HerbMon 9
• STPLYoutube
• ZZZeroYoutube
• BSLYoutube
League of Legends
• Nemesis2646
• TFBlade731
Other Games
• Shiphtur420
• imaqtpie0
Upcoming Events
Replay Cast
14h 36m
CrankTV Team League
16h 36m
WardiTV Qualifier
17h 36m
Epic.LAN
18h 36m
Big Brain Bouts
21h 36m
SHIN vs Elazer
Percival vs Nicoract
Reynor vs Lambo
Replay Cast
1d 5h
RSL Revival
1d 14h
Clem vs Lambo
Scarlett vs Cure
CranKy Ducklings
1d 15h
Epic.LAN
1d 18h
IPSL
1d 21h
Dragon vs Hawk
[ Show More ]
RSL Revival
2 days
Classic vs Trap
herO vs SHIN
Sparkling Tuna Cup
2 days
IPSL
2 days
Bonyth vs Ret
WardiTV Weekly
3 days
Monday Night Weeklies
3 days
PiGosaur Cup
5 days
The PondCast
5 days
Replay Cast
6 days
CrankTV Team League
6 days
Liquipedia Results

Completed

Proleague 2026-07-13
HSC XXIX
Eternal Conflict S2 E2

Ongoing

IPSL Spring 2026
Acropolis #4
CSL 2026 Summer (S21)
KCM Race Survival 2026 Season 3
RSL Revival: Season 6
CranK Gathers Season 4: BW vs SC2 Team League
SCTL 2026 Spring
Stake Ranked Episode 3
XSE Pro League 2026
IEM Cologne Major 2026
Stake Ranked Episode 2
CS Asia Championships 2026
Asian Champions League 2026
IEM Atlanta 2026
PGL Astana 2026
BLAST Rivals Spring 2026

Upcoming

Escore Tournament S3: W3
ASL S22 SEASON OPEN Day 1
Escore Tournament S3: W4
ASL S22 SEASON OPEN Day 2
Escore Tournament S3: W5
CSLAN 4
Blizzard Classic Cup 2026
HSC XXX
SC4ALL II: StarCraft II
Kung Fu Cup 2026 Grand Finals
Light Tournament 2026
Eternal Conflict S2 Finale
Eternal Conflict S2 E3
Logitech G Connect 2026
StarSeries Fall 2026
FISSURE Playground #5
BLAST Open Fall 2026
Esports World Cup 2026
BLAST Bounty Summer 2026
BLAST Bounty Summer Qual
TLPD

1. ByuN
2. TY
3. Dark
4. Solar
5. Stats
6. Nerchio
7. sOs
8. soO
9. INnoVation
10. Elazer
1. Rain
2. Flash
3. EffOrt
4. Last
5. Bisu
6. Soulkey
7. Mini
8. Sharp
Sidebar Settings...

Advertising | Privacy Policy | Terms Of Use | Contact Us

Original banner artwork: Jim Warren
The contents of this webpage are copyright © 2026 TLnet. All Rights Reserved.