• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 14:44
CEST 20:44
KST 03:44
  • 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
TL.net Map Contest #21: Voting6[ASL20] Ro4 Preview: Descent11Team TLMC #5: Winners Announced!3[ASL20] Ro8 Preview Pt2: Holding On9Maestros of the Game: Live Finals Preview (RO4)5
Community News
Weekly Cups (Oct 6-12): Four star herO65.0.15 Patch Balance Hotfix (2025-10-8)78Weekly Cups (Sept 29-Oct 5): MaxPax triples up3PartinG joins SteamerZone, returns to SC2 competition325.0.15 Balance Patch Notes (Live version)119
StarCraft 2
General
How to Block Australia, Brazil, Singapore Servers 5.0.15 Patch Balance Hotfix (2025-10-8) Revisiting the game after10 years and wow it's bad TL.net Map Contest #21: Voting The New Patch Killed Mech!
Tourneys
Crank Gathers Season 2: SC II Pro Teams LiuLi Cup - September 2025 Tournaments SC4ALL $6,000 Open LAN in Philadelphia Sparkling Tuna Cup - Weekly Open Tournament Master Swan Open (Global Bronze-Master 2)
Strategy
Custom Maps
External Content
Mutation # 495 Rest In Peace Mutation # 494 Unstable Environment Mutation # 493 Quick Killers Mutation # 492 Get Out More
Brood War
General
[Interview] Grrrr... 2024 BW caster Sayle BW General Discussion Map with fog of war removed for one player? Pros React To: BarrackS + FlaSh Coaching vs SnOw
Tourneys
[ASL20] Semifinal B [ASL20] Semifinal A SC4ALL $1,500 Open Bracket LAN [Megathread] Daily Proleagues
Strategy
Relatively freeroll strategies Current Meta BW - ajfirecracker Strategy & Training Siegecraft - a new perspective
Other Games
General Games
Stormgate/Frost Giant Megathread Dawn of War IV Nintendo Switch Thread ZeroSpace Megathread Path of Exile
Dota 2
Official 'what is Dota anymore' discussion LiquidDota to reintegrate into TL.net
League of Legends
Heroes of the Storm
Simple Questions, Simple Answers Heroes of the Storm 2.0
Hearthstone
Deck construction bug Heroes of StarCraft mini-set
TL Mafia
SPIRED by.ASL Mafia {211640} TL Mafia Community Thread
Community
General
US Politics Mega-thread Russo-Ukrainian War Thread Things Aren’t Peaceful in Palestine Men's Fashion Thread Sex and weight loss
Fan Clubs
The herO Fan Club! The Happy Fan Club!
Media & Entertainment
[Manga] One Piece Series you have seen recently... Anime Discussion Thread Movie Discussion!
Sports
2024 - 2026 Football Thread Formula 1 Discussion MLB/Baseball 2023 NBA General Discussion TeamLiquid Health and Fitness Initiative For 2023
World Cup 2022
Tech Support
SC2 Client Relocalization [Change SC2 Language] Linksys AE2500 USB WIFI keeps disconnecting Computer Build, Upgrade & Buying Resource Thread
TL Community
The Automated Ban List Recent Gifted Posts
Blogs
Inbreeding: Why Do We Do It…
Peanutsc
From Tilt to Ragequit:The Ps…
TrAiDoS
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1697 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
Germany2578 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
Next event in 16h 16m
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
UpATreeSC 251
BRAT_OK 97
JuggernautJason68
Railgan 35
ForJumy 24
MindelVK 17
StarCraft: Brood War
Britney 23288
Calm 3766
Larva 446
firebathero 247
Hyun 84
Barracks 60
scan(afreeca) 20
Movie 15
NaDa 6
Dota 2
canceldota45
Counter-Strike
fl0m1299
Foxcn187
Heroes of the Storm
XaKoH 98
Other Games
Grubby1929
ceh9631
Beastyqt532
B2W.Neo331
KnowMe169
crisheroes166
C9.Mang0150
ArmadaUGS109
Hui .103
ToD101
Pyrionflax90
Dewaltoss27
Organizations
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 16 non-featured ]
StarCraft 2
• intothetv
• AfreecaTV YouTube
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• blackmanpl 35
• 80smullet 14
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
Dota 2
• C_a_k_e 3484
League of Legends
• TFBlade806
Other Games
• imaqtpie1614
• Shiphtur317
Upcoming Events
Wardi Open
16h 16m
CranKy Ducklings
1d 15h
Safe House 2
1d 22h
Sparkling Tuna Cup
2 days
Safe House 2
2 days
Tenacious Turtle Tussle
6 days
The PondCast
6 days
Liquipedia Results

Completed

Acropolis #4 - TS2
WardiTV TLMC #15
HCC Europe

Ongoing

BSL 21 Points
ASL Season 20
CSL 2025 AUTUMN (S18)
C-Race Season 1
IPSL Winter 2025-26
EC S1
Thunderpick World Champ.
CS Asia Championships 2025
ESL Pro League S22
StarSeries Fall 2025
FISSURE Playground #2
BLAST Open Fall 2025
BLAST Open Fall Qual
Esports World Cup 2025
BLAST Bounty Fall 2025
BLAST Bounty Fall Qual
IEM Cologne 2025

Upcoming

SC4ALL: Brood War
BSL Season 21
BSL 21 Team A
RSL Offline Finals
RSL Revival: Season 3
Stellar Fest
SC4ALL: StarCraft II
CranK Gathers Season 2: SC II Pro Teams
eXTREMESLAND 2025
ESL Impact League Season 8
SL Budapest Major 2025
BLAST Rivals Fall 2025
IEM Chengdu 2025
PGL Masters Bucharest 2025
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 © 2025 TLnet. All Rights Reserved.