How to properly plan a program?

Pages: 12
closed account (z0My6Up4)
Zorg wrote:
...I'm struggling to understand what I am supposed to be doing. I had a great idea in my head but I feel like I just can't get it into code. I might just have to give up with it for a few years until I fully understand what C++ is about...


Don't give up Zorg. You are doing a good thing in attempting to write a real program. You can spend years mulling over textbooks and learning the syntax, but until you actually try to code something it can be tough understanding what it is really all about. The inventor of C++ says in his book that "the best way to learn a new language is to write programs in it". Keep going and you will learn a lot.

I would suggest though that you spend some time doing a very brief & informal requirements & design document. You can then identify the various modules and the interfaces that exist between the modules. Once you have figured that out it will be a lot easier to start writing code.

good luck
IRC is Internet Relay Chat. It's been around forever, and still fairly popular. A bot is a program which connects to IRC and does whatever you want really. It's a fun project. If I had to bet, most of us here have made at least one IRC bot at some point. There's actually two or three sitting in the #cplusplus channel right now.

As for getting on IRC, you need a client. If you want to just get going, then go here: http://webchat.quakenet.org/

It's super basic, but it works. Just join the channel #cplusplus, and pick whatever nickname you want.

If you want something more robust, then grab a standalone client. HexChat is a very solid and popular client.
closed account (L6b7X9L8)
Flint:
I would suggest though that you spend some time doing a very brief & informal requirements & design document. You can then identify the various modules and the interfaces that exist between the modules. Once you have figured that out it will be a lot easier to start writing code.


Could you elaborate a little on this please? I've been writing down ideas and such, but I'm struggling to understand how it all fits together.

I know I need some players, a map, an interface screen and a shop.

The user starts off on the interface screen where they can choose to buy parts, put their robot together, program their bot ( This is the sucky part I REALLY have no idea how to do, but I think it would be a fun game mechanic rather then the over used aim and shoot system ) and go fight other bots in the arena.

How would I plan all this exactly? I know what I want, I just have no clue how I should go about doing it.

///////////////////////////////////////////////////////////////

Thanks for that ResidentBiscuit, I came across this link while researching : http://beej.us/guide/bgnet/output/html/singlepage/bgnet.html

It all seems way over my head making an IRC Bot though it does look fun to code.
closed account (z0My6Up4)
I think it would help if you put down on paper a list of the main system and user requirements that must be in your program. In software engineering it is a way of specifying what the program should do. I'm not suggesting that you need to go into planning every detail, but do spend some time thinking about:

a) What are the user requirements
- A user must be able to choose to buy parts
- A user must be able to pass instructions to their bot
etc..

b) System requirements
- The program must display xyz instructions to the user
- The program must display a 2D map
etc..

Now if you list all of main the user & system requirements methodically like this, you will then be in a position to write up a short design document. That is a specification of all of the modules that your program might need to meet the requirements and it is at this stage that you can think about how the different parts work together. I have found it most helpful to draw diagrams of the modules. From there, you can start to identify what the main classes & functions of the program will be. If you spend a lot of time thinking and planning your game, the coding part will follow a lot more naturally than you may think. Try not to rush this stage - a couple of days thinking about it would be great.

You can find good information on software design on the net. A good book that I have is "Software Engineering" by Sommerville. You probably don't need a book though as there lots of info online that will help you develop your game in this way.
hth
Last edited on
It all seems way over my head making an IRC Bot though it does look fun to code

As excellent as Beej's guide to network programming is, it's unnecessary for this task.

If an IRC bot looks interesting, I suggest grabbing Python or Ruby at first. They both have extremely simple networking modules which can you get you used to network programming and the IRC protocol.

For example, this is a bot which just connects to a server, joins a channel, then just sits there. Written in Python.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import socket
import sys
import re
 
server = "irc.freenode.net"
channel = "#botwar"
nick = "ResidentBot"
user = "ResidentBiscuit"
 
irc_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
 
irc_socket.connect((server, 6667))
#IRC connection handshake consists of sending NICK and USER messages. All IRC messages must end in \r\n
irc_socket.send("NICK " + nick + "\r\nUSER " + user + " 0 * :" + nick + "\r\n")
irc_socket.send("JOIN " + channel + "\r\n")

while True:
	recv_text = irc_socket.recv(1024)
	sys.stdout.write(recv_text)
	# Servers send occasional pings that must be replied to, else get kicked
	if recv_text.find("PING"):
		irc_socket.send("PONG " + recv_text.split()[1] + "\r\n")
closed account (L6b7X9L8)
Sorry for my late responses guys.

@flint

Thank you for the information, I have your response copied and saved in a txt for reference. I am going to scrap my project and try and figure out every damn detail before I start coding. I am also trying to get used to SFML to see if that can help me code my game easier ( Though I am not getting very far. :P )


@ResidentBiscuit

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import socket
import sys
import re
 
server = "irc.freenode.net"
channel = "#botwar"
nick = "ResidentBot"
user = "ResidentBiscuit"
 
irc_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
 
irc_socket.connect((server, 6667))
#IRC connection handshake consists of sending NICK and USER messages. All IRC messages must end in \r\n
irc_socket.send("NICK " + nick + "\r\nUSER " + user + " 0 * :" + nick + "\r\n")
irc_socket.send("JOIN " + channel + "\r\n")

while True:
	recv_text = irc_socket.recv(1024)
	sys.stdout.write(recv_text)
	# Servers send occasional pings that must be replied to, else get kicked
	if recv_text.find("PING"):
		irc_socket.send("PONG " + recv_text.split()[1] + "\r\n")


Well that looks x1000 times less effort, and I can weirdly understand it and I haven't done Python before. The only lines that I can't decipher are:

1
2
3
irc_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) #AF_INET & SOCK_STREAM?

irc_socket.send("PONG " + recv_text.split()[1] + "\r\n") #Mainly recv_text.split()[1] 


If you are sending strings to the IRC server with 'NICK' and 'USER', does this mean the IRC interprets the information it receives?

Also are you suggesting I should scrap C++ and go for Python instead? I have recently installed SFML which has a networking module which ( Maybe ) has it's own wrapper class for this sort of stuff to make it easier, do you have any experience?
Oh if you installed SFML then just use that. The networking module on SFML is about as easy as it is on Python. I think I even have an example of an IRC bot using SFML somewhere too...

If you are sending strings to the IRC server with 'NICK' and 'USER', does this mean the IRC server interprets the information it receives?

Yup. That's why we have protocols :)

1
2
3
irc_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM
#AF_INET just says this is an Internet socket, ie IP
#SOCK_STREAM says basically to use TCP instead of UDP (should know the difference :) ) 


1
2
3
4
5
6
irc_socket.send("PONG " + recv_text.split()[1] + "\r\n") #Mainly recv_text.split()[1]
#This code is what handles the server's ping requests. The format of a ping request is 'PING :somecharacters' and the reply must be 'PONG "somecharacters'
#So, the recv_text.split() part splits the PING message into tokens, delimited by spaces
#The [1] part says grab the 2nd element of that array of tokens (0 indexed), which would be the ':somecharacters'

#Then we send this new string which is 'PONG :somecharacters' :) 
Last edited on
closed account (L6b7X9L8)
That's great! If you could fish out that example for me I would be very grateful :) I would try to add a way for me to send messages while I am logged in too!

Be warned though I installed SFML a few hours ago and did a simple graphics program before I went to sleep ( It was a snowman, Disch helped me do it, man that dude is real smart isn't he? ) so I have the intelligence of a slug when it comes to SFML.


I think I understand the basics of TCP and UDP:

TCP is a lossless transmission protocol for when things need to arrive without corruption, there is sometimes a delay so it isn't used for real time services.

And UDP is a protocol where the packets may not always arrive perfectly or even arrive at all, it has less overhead than the TCP and is used for real time communication ( I am guess that's like voice chat or video calls? )


Regards to the:

irc_socket.send("PONG " + recv_text.split()[1] + "\r\n")

is recv_text a string then? Because it seems Python doesn't identify a type to it's variables? Which then makes sense if recv_text()[0] is "PING" and the rest of the elements a string literals, then that makes perfect sense to me.
Disch helped me do it, man that dude is real smart isn't he?

He is very smart!

You pretty much got all you need to know about TCP and UDP. TCP is reliable, UDP is unreliable. TCP is slower, UDP is faster.

is recv_text a string then?

It is, yeah.

Python doesn't identify a type to it's variables?

You got it! Dynamically typed languages are sometimes tricky for people to grasp when coming from a statically typed language (C++ for example)

Hop on IRC if you want to chat more. I'll be there all day.
closed account (N36fSL3A)
I've only just glanced at this thread, I just wanted to add on that SFML has a great networking library (It's actually my favorite), so you can write an IRC bot with the library.
closed account (j3Rz8vqX)
It's a really good object oriented library to develop with.

And the best part is its "well" documentation!

http://www.sfml-dev.org/documentation/2.0/classes.php
Last edited on
closed account (z0My6Up4)
If your still planning on doing this, I read a good short introductory paper that will help on this topic. Here is the link:
http://www.cs.tufts.edu/comp/40/handouts/design.pdf
closed account (L6b7X9L8)
@Fredbill & Dput

Thanks for the information, I have recently moved to Linux by popular opinion on the IRC ( Though the distro I got didn't get the same treatment :) ) so I don't have SFML anymore :/

@flint

I am still figuring out the angles to my game so any links are well appreciated! I am checking it out now thank you

closed account (z0My6Up4)
Why don't you have SFML? I thought it worked on all Linux systems. I installed it easily on my debian system.
^

You can install SFML on Debian no problem. It may even be in the repo's, though if I had to guess they don't have v2.x in the repos yet.

Either way, you can just download it and set it up yourself. It's not too hard.
It works on all distros as far as I know, but some distros have the lib and files in their repository so you just have to do something like
sudo apt-get install sfml-dev
. If his distro doesn't have it or isn't up-to-date, it is still just a matter of installing the tools and any libraries he needs, getting the library source to build it and install it.

[EDIT]
Heh, hit reply and walked away from laptop. While I was away ResidentBiscuit answered it. Just making note of this so it doesn't appear I am trying explain RBs reply or anything.
Last edited on
closed account (z0My6Up4)
I installed SFML on debian and it took only around 20 - 30 minutes to find & download all the dependencies and then to compile & build the latest version using cmake. I just followed the instruction in the sfml tutorial to set it up.
closed account (L6b7X9L8)
I haven't got SFML anymore because I haven't thought about installing it, that's all guys :)

I've been working on my emulator a fair bit ( Pretty much since I installed Debian ) so that's been taking up my time.

I got informed about a great site called GitHub ( Thanks RB and DTSCode ) so if fancy adding to it feel free!:

https://github.com/ZorgSpace/CPU_1001A/

[/advertisement]

I will go about installing SFML either today or over the weekend. I have no experience with 'Make' or anything like that.

Also I downloaded the new G++ I have to compile :/
closed account (z0My6Up4)
Well when you do install it I don't recommend you use the debian repository version as it is really old -something like 1.6. There are still tutorials for this, but the latest release is version 2.1. cmake-gui is the program that is used to build sfml. It is all explained in the sfml tutorial 'compiling with cmake'.
Topic archived. No new replies allowed.
Pages: 12