Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Validation checking
#9
(Aug-14-2019, 03:41 PM)Help_me_Please Wrote: I want to create a 4 in a row game which I can adapt to make it harder, but I want to create a game board using a 2D array, I want to create a validation method by checking the column selected is within the correct parameters. I need to fix the error given.

I concur with jefsummers and suggest of doing some planning.

For me there is still ambiguity:

- what is '4 in a row game'?
- for what and how game board will be used?
- do you need check only columns (and not rows)?

EDIT:

Some additional observations to jefsummers: at any cost try to avoid this:

# code
columns = 6
# some more code
def is_valid_location(board, column):
    if column > 6 or column <= 0:
        invalid = True
At some point in future you decide that board should have 8 columns instead of 6. You will change 'columns' value and expect your code to work same. But validation function doesn't know anything about columns. There is hardcoded 6 which is checked. As this is buried in body of function this bug will be hard to trace. Never hardcode.

For readability purposes you can instead of if column > 6 or column <=0: write if columns < column <= 0.
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply


Messages In This Thread
Validation checking - by Help_me_Please - Aug-14-2019, 01:31 PM
RE: Validation checking - by buran - Aug-14-2019, 01:35 PM
RE: Validation checking - by perfringo - Aug-14-2019, 01:39 PM
RE: Validation checking - by Help_me_Please - Aug-14-2019, 01:43 PM
RE: Validation checking - by perfringo - Aug-14-2019, 01:52 PM
RE: Validation checking - by Help_me_Please - Aug-14-2019, 03:41 PM
RE: Validation checking - by perfringo - Aug-14-2019, 07:55 PM
RE: Validation checking - by ichabod801 - Aug-14-2019, 05:01 PM
RE: Validation checking - by jefsummers - Aug-14-2019, 06:39 PM
RE: Validation checking - by Help_me_Please - Aug-15-2019, 02:17 PM
RE: Validation checking - by ichabod801 - Aug-15-2019, 03:06 PM
RE: Validation checking - by Help_me_Please - Aug-15-2019, 03:33 PM
RE: Validation checking - by ichabod801 - Aug-15-2019, 03:36 PM
RE: Validation checking - by Help_me_Please - Aug-15-2019, 04:03 PM
RE: Validation checking - by buran - Aug-15-2019, 04:51 PM
RE: Validation checking - by ichabod801 - Aug-15-2019, 04:54 PM
RE: Validation checking - by Help_me_Please - Aug-16-2019, 09:40 AM
RE: Validation checking - by perfringo - Aug-16-2019, 10:17 AM
RE: Validation checking - by jefsummers - Aug-16-2019, 11:46 AM
RE: Validation checking - by perfringo - Aug-16-2019, 12:11 PM
RE: Validation checking - by ichabod801 - Aug-16-2019, 12:33 PM
RE: Validation checking - by Help_me_Please - Aug-16-2019, 12:46 PM
RE: Validation checking - by jefsummers - Aug-16-2019, 02:18 PM
RE: Help please stuck with summer work - by nilamo - Aug-15-2019, 04:47 PM
Connect 4 - by Help_me_Please - Aug-16-2019, 11:38 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020