Home | Community | Message Board

Out-Grow.com - Mushroom Growing Kits & Supplies
This site includes paid links. Please support our sponsors.


Welcome to the Shroomery Message Board! You are experiencing a small sample of what the site has to offer. Please login or register to post messages and view our exclusive members-only content. You'll gain access to additional forums, file attachments, board customizations, encrypted private messages, and much more!

Shop: Bridgetown Botanicals CBD Concentrates   MagicBag.co All-In-One Bags That Don't Suck   Kraken Kratom Red Vein Kratom   PhytoExtractum Kratom Powder for Sale   Mushroom-Hut Grow Bags   Unfolding Nature Unfolding Nature: Being in the Implicate Order

Jump to first unread post Pages: 1
OfflineSleepyE
DMT is metaphysical
Male User Gallery


Registered: 07/21/08
Posts: 8,760
Loc: Ontario, Canada, Flag
Last seen: 3 days, 11 hours
Ive been doing c++ coding challenges * 2
    #28630425 - 01/21/24 08:36 PM (3 months, 25 days ago)

So, ive been doing these c++ programming challenges lately, the rules are that I have a given project and i have to complete it without the use of outside resources, basically done without internet. This means no stackoverflow, no chatGPT, etc.. It needs to be completed with only the knowledge that I have. Its a way to actually improve my problem solving abilities i think.

For context by the way, im in my 4th semester at Sheridan College in Oakville Ontario for Computer Programming, its a 2 year program. I havent had any classes for c++ unfortunately but since its my favourite language im learning it on the side instead.
(My School/course info)
https://www.sheridancollege.ca/programs/computer-programming

(Video Demo of my application working and showcasing features)


This challenge is to program a fully functional checkered board game on a 2-dimensional array.
The 2-dimensional array method of displaying the board is proposed in the challenge video
"C++/Game Tutorial 15: Checkerboard With 2D Array And Modulus!"

where he gives the starting point of the project by initializing and printing the empty board.
My task is to place the pieces on the board and code the complete game logic.
Not going to lie it took quite a while with all the debugging i had to do. Writing algorithms based on a 2-dimensional array/matrix is extremely tedious and finicky.
The next task is to add AI functionality to it so its a single player game, though i hope coding a basic AI opponent isnt too advanced for me.
I Uploaded the c++ source code to my gitHub for public viewing so you can check it out if you like!

(Most of the code is in the CheckerBoard.cpp file so definitely start with this one first.)
https://github.com/TylerMaster/ICE1/blob/BRANDON_SMITH_Ex1/CheckerBoard.cpp

https://github.com/TylerMaster/ICE1/blob/BRANDON_SMITH_Ex1/CheckerBoard.h

https://github.com/TylerMaster/ICE1/blob/BRANDON_SMITH_Ex1/ConsoleApplication5.cpp

https://github.com/TylerMaster/ICE1/blob/BRANDON_SMITH_Ex1/PlayerPiece.cpp

https://github.com/TylerMaster/ICE1/blob/BRANDON_SMITH_Ex1/PlayerPiece.h

https://github.com/TylerMaster/ICE1/blob/BRANDON_SMITH_Ex1/PlayerPiece2.cpp

https://github.com/TylerMaster/ICE1/blob/BRANDON_SMITH_Ex1/PlayerPiece2.h


When i finally finished the code I posted it into chatgpt and ask it to explain/summarize my code and this is what it had to say!

Quote:

The provided C++ code demonstrates several fundamental programming concepts and practices. Here are some of the key programming fundamentals involved:
    Object-Oriented Programming (OOP):
        The code is organized using classes (CheckerBoard, PlayerPiece, and PlayerPiece2) to encapsulate related data and behavior.
        Objects of these classes are created to represent the game board and player pieces, promoting code modularity and reusability.
    Control Flow:
        The game flow is controlled by loops (while loops) and conditional statements (if, else if, else).
        The program uses control flow to handle player turns, validate user input, and check for winning conditions.
    Functions and Methods:
        The code is modularized into functions and methods, promoting code organization, readability, and maintainability.
        Functions are used for various purposes, such as initializing the board, printing the board, handling player turns, and checking for winning conditions.
    Arrays and Data Structures:
        A 2D array (board) is used to represent the checkerboard.
        The array is manipulated to place player pieces, update the board state, and check for winning conditions.
    Input and Output Handling:
        The code uses standard input/output (cin and cout) for user input and displaying information.
        Input validation is performed to ensure users provide valid input when selecting and moving pieces.
    Conditional Statements:
        The code uses conditional statements to check various conditions, such as whether a move is valid, if a player has won, or if a piece can capture an opponent's piece.
    Loops:
        while loops are employed for the main game loop and nested loops for specific tasks, such as input validation and multiple hits during a turn.
    Variable Declaration and Initialization:
        Variables are declared and initialized to store information such as player symbols, coordinates, and flags.
    Error Handling:
        The code includes some error handling, such as checking for valid input coordinates and informing the user about invalid moves.
    Code Organization and Readability:
        The code is organized into functions and classes, improving readability and maintainability.
        Descriptive variable and function names are used to enhance code understanding.
    Logical Operations:
        Logical operations (&&, ||) are used in conditional statements to combine multiple conditions for decision-making.
    Code Reusability:
        The use of classes and functions promotes code reusability, allowing similar functionality to be easily extended or reused in different parts of the program.
    Increment and Decrement Operators:
        Increment (++) and decrement (--) operators are used to modify loop control variables.
These fundamentals collectively contribute to the development of a structured, readable, and functional program for a simple checkers game.




--------------------
My Drawingzz
Draw DMT!

Trip Report: SHROOMS DMT---- My Youtube Psychedelic Channel

Edited by SleepyE (01/21/24 11:08 PM)

Extras: Filter Print Post Top
Invisiblekoraks
Registered: 06/02/03
Posts: 26,729
Re: Ive been doing c++ coding challenges [Re: SleepyE]
    #28630587 - 01/22/24 12:58 AM (3 months, 25 days ago)

Quote:

SleepyE said:
When i finally finished the code I posted it into chatgpt and ask it to explain/summarize my code and this is what it had to say!




:needssalt:

Goes to show that ChatGTP isn't very useful in evaluating assignments etc.

I haven't looked at everything, but a quick peek suggests that there are far more elegant solutions than the proliferation of highly redundant functions you define in CheckerBoard.h lines 41-73.

It also looks like you haven't leveraged the use of arrays, lists or other types of containers yet, going by a quick peek at CheckerBoard.cpp, which is also rich in highly redundant and repetitive code.

What's the point in having two identical classes (PlayerPiece & PlayerPiece2)?

Here's a suggestion: when making a new function and you find yourself copying an existing function and adjusting a few bits here and there, you're creating redundancy in your code and probably overlooking a more elegant solution. Mind you, highly redundant code is sometimes preferable for performance issues, but in this type of application and the type of exercise you're doing, it certainly isn't.

Extras: Filter Print Post Top
OfflineSleepyE
DMT is metaphysical
Male User Gallery


Registered: 07/21/08
Posts: 8,760
Loc: Ontario, Canada, Flag
Last seen: 3 days, 11 hours
Re: Ive been doing c++ coding challenges [Re: koraks]
    #28630595 - 01/22/24 01:39 AM (3 months, 25 days ago)

yeah i definitely have to simplify my code. I was more concerned with getting it working. the simplifying of repetitive code has to come after. I think it will be a good exercise though!


--------------------
My Drawingzz
Draw DMT!

Trip Report: SHROOMS DMT---- My Youtube Psychedelic Channel

Extras: Filter Print Post Top
Invisiblekoraks
Registered: 06/02/03
Posts: 26,729
Re: Ive been doing c++ coding challenges [Re: SleepyE] * 1
    #28630605 - 01/22/24 02:01 AM (3 months, 25 days ago)

Quote:

SleepyE said:
yeah i definitely have to simplify my code. I was more concerned with getting it working. the simplifying of repetitive code has to come after. I think it will be a good exercise though!



Sure. It's good to make both things go hand in hand though. After the first handful of exercises, you really need to be able to solve the problem in an efficient way. If you don't, you'll be stuck with a high level of redundancy and that will stand in the way of doing more complex programs. You hit that wall pretty quickly.

Extras: Filter Print Post Top
OfflineSleepyE
DMT is metaphysical
Male User Gallery


Registered: 07/21/08
Posts: 8,760
Loc: Ontario, Canada, Flag
Last seen: 3 days, 11 hours
Re: Ive been doing c++ coding challenges [Re: koraks]
    #28630607 - 01/22/24 02:10 AM (3 months, 25 days ago)

Agreed, honestly i was trying to not have the redundances but when i tried to handle those all in one function i was running into issues that i wasnt seeing the reason for during my debugging phase. so instead of wasting time trying to get it working i just split up the tasks in seperate functions so that nothing is conflicting and i had more control over what actions were happening in what order. I hated that i was doing it and felt gross haha.

also I had flag console output comments everywhere to check the value of variables before/after they were passed into functions, it got very messy and hard to follow/trace without them.

Now that its running fine i can just slowly hack away at simplifying those while making sure its still functioning correctly.


--------------------
My Drawingzz
Draw DMT!

Trip Report: SHROOMS DMT---- My Youtube Psychedelic Channel

Edited by SleepyE (01/22/24 05:22 PM)

Extras: Filter Print Post Top
Invisiblekoraks
Registered: 06/02/03
Posts: 26,729
Re: Ive been doing c++ coding challenges [Re: SleepyE] * 1
    #28630613 - 01/22/24 02:20 AM (3 months, 25 days ago)

Two things will make a major difference:

1: Arrays and other containers (https://en.cppreference.com/w/cpp/container)

2: Finite state machines (e.g. https://www.aleksandrhovhannisyan.com/blog/implementing-a-finite-state-machine-in-cpp/)

Extras: Filter Print Post Top
OfflineSleepyE
DMT is metaphysical
Male User Gallery


Registered: 07/21/08
Posts: 8,760
Loc: Ontario, Canada, Flag
Last seen: 3 days, 11 hours
Re: Ive been doing c++ coding challenges [Re: koraks]
    #28631277 - 01/22/24 05:20 PM (3 months, 24 days ago)

i definitely was thinking about using arrays but during the development I was thinking more about what was going to work for me at the moment instead of thinking what would be the most optimal (that is definitely going to come with more experience). My approach was to keep things as basic as possible to get the game logic running and then go in and make upgrades to the code including doing the simplifying.
I am lucky that it was designed in a way where I can make these adjustments without any major complications.



--------------------
My Drawingzz
Draw DMT!

Trip Report: SHROOMS DMT---- My Youtube Psychedelic Channel

Edited by SleepyE (01/22/24 05:28 PM)

Extras: Filter Print Post Top
Invisibleredgreenvines
irregular verb
 User Gallery

Registered: 04/08/04
Posts: 38,510
Re: Ive been doing c++ coding challenges [Re: SleepyE] * 1
    #28646498 - 02/04/24 02:22 PM (3 months, 11 days ago)



--------------------
:confused: _ :brainfart:🧠  _ :finger:

Extras: Filter Print Post Top
OfflineSleepyE
DMT is metaphysical
Male User Gallery


Registered: 07/21/08
Posts: 8,760
Loc: Ontario, Canada, Flag
Last seen: 3 days, 11 hours
Re: Ive been doing c++ coding challenges [Re: redgreenvines]
    #28654640 - 02/10/24 07:49 PM (3 months, 5 days ago)

ayy didnt notice you posted :P
Quote:

redgreenvines said:
https://stackoverflow.com/questions/18216988/creating-two-dimensional-array-of-class

looks like a similar situation point 5. has answers




interesting! il take a looksee :awesomenod:


--------------------
My Drawingzz
Draw DMT!

Trip Report: SHROOMS DMT---- My Youtube Psychedelic Channel

Extras: Filter Print Post Top
Jump to top Pages: 1

Shop: Bridgetown Botanicals CBD Concentrates   MagicBag.co All-In-One Bags That Don't Suck   Kraken Kratom Red Vein Kratom   PhytoExtractum Kratom Powder for Sale   Mushroom-Hut Grow Bags   Unfolding Nature Unfolding Nature: Being in the Implicate Order


Similar ThreadsPosterViewsRepliesLast post
* Go to the store and name your price! with re-code.com
( 1 2 all )
Lana 4,340 39 06/03/03 10:22 AM
by Raadt
* Coding Theory HighTek 581 2 03/11/09 04:42 PM
by HighTek
* Why is coding cool?
( 1 2 all )
Epigallo 1,478 20 02/11/09 04:42 PM
by PlayDoh
* . dr_gonz 1,030 12 04/13/05 12:36 PM
by lackobreath
* Microsoft Office Key Code Banez 1,127 5 05/12/07 04:25 AM
by Banez
* spaghettification of code...
( 1 2 all )
Annapurna1 2,444 34 10/08/08 04:12 PM
by ExplosiveMango
* Designing Codes, Possible to make undecipherable?
( 1 2 all )
HagbardCeline 4,186 20 08/31/03 07:49 PM
by Mal_Fenderson
* Crack this code! It should be easy!
( 1 2 all )
gir 2,407 22 06/06/03 03:12 AM
by SHiZNO

Extra information
You cannot start new topics / You cannot reply to topics
HTML is disabled / BBCode is enabled
Moderator: trendal, automan, Northerner
215 topic views. 0 members, 0 guests and 0 web crawlers are browsing this forum.
[ Show Images Only | Sort by Score | Print Topic ]
Search this thread:

Copyright 1997-2024 Mind Media. Some rights reserved.

Generated in 0.024 seconds spending 0.005 seconds on 12 queries.