Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed overlapping digits #15 #18

Merged
merged 9 commits into from
Apr 4, 2021
Merged

fixed overlapping digits #15 #18

merged 9 commits into from
Apr 4, 2021

Conversation

sourabhaa
Copy link
Contributor

@sourabhaa sourabhaa commented Mar 25, 2021

Summary

Fixes #15. When the number falls in each iteration (each question), the multiple wrong options does not overlap over each other and over the right answer. Also, the right answer appears on different co-ordinates in each iteration. I have limited the number of options to six.
The activity works fine when played in easy, medium and difficult mode.
Tested on Sugar Desktop 0.117, Ubuntu 20.10.

JAMath_medium_ss

Copy link
Member

@chimosky chimosky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, reviewed and tested.

juego.py Outdated
list_x = [int(sx(100)),int(sx(200)),int(sx(300)),int(sx(400)),int(sx(500)),int(sx(600)),int(sx(700)),
int(sx(800)),int(sx(900))]
def rand_generator_x():
count_x=0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you space the assignment operator from the variable name and value, helps with readability.

juego.py Outdated
int(sx(800)),int(sx(900))]
def rand_generator_x():
count_x=0
while(count_x<len(list_x)):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This too and you don't need the outer parentheses.

juego.py Outdated
count_x=0
while(count_x<len(list_x)):
rand_coord_x = random.choice(list_x)
count_x+=1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This too.

juego.py Outdated
while(count_x<len(list_x)):
rand_coord_x = random.choice(list_x)
count_x+=1
if(rand_coord_x not in no_repeat_check_x):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for the parentheses here too.

juego.py Outdated
count_x+=1
if(rand_coord_x not in no_repeat_check_x):
no_repeat_check_x.append(rand_coord_x)
return(rand_coord_x)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This too.

juego.py Outdated
Comment on lines 43 to 45
list_y = [int(sx(-50)),int(sx(-40)),int(sx(-30)),int(sx(-10)),int(sx(-20)),int(sx(-0)),int(sx(-60)),int(sx(-65))]
list_x = [int(sx(100)),int(sx(200)),int(sx(300)),int(sx(400)),int(sx(500)),int(sx(600)),int(sx(700)),
int(sx(800)),int(sx(900))]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any reason why list_x has more values than list_y?

Copy link
Contributor Author

@sourabhaa sourabhaa Mar 27, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for reviewing. There is no pressing reason as such. Since the x and y coordinates are chosen randomly and independent of each other, availing only 6 coordinates would serve the purpose. My intention is to cover the entire screen, hence the x- coordinates ranges from 100 to 900. The purpose of slightly varying the y coordinates is to prevent the overlapping, if the multiple 4 digit number appears consecutively.The difference in the number of values wouldn't be of much concern to the output. However, I will consider adding one more value to list_y which might as well increase a possibility.

juego.py Outdated
if(rand_coord_x not in no_repeat_check_x):
no_repeat_check_x.append(rand_coord_x)
return(rand_coord_x)
break
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to break as there's a return statement.

juego.py Outdated
Comment on lines 56 to 65
def rand_generator_y():
count_y=0
while(count_y<len(list_y)):
count_y+=1
rand_coord_y = random.choice(list_y)
if(rand_coord_y not in no_repeat_check_y):
no_repeat_check_y.append(rand_coord_y)
return(rand_coord_y)
break
return int(sx(-3))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comments as rand_generator_x above.

juego.py Outdated
ans_x_coord = rand_generator_x()
ans_y_coord = rand_generator_y()
self.preguntas.add(number(ans_x_coord,ans_y_coord, fuente.render(self.resultado,True,
(random.randint(0,255),random.randint(0,255),random.randint(0,255))),True))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also kindly remove the extra spaces at the end of the line.

juego.py Outdated
if random.randint(0,1) == 0:
wrong = str(int(self.resultado) - random.randint(1,10))
wrong = str(int(self.resultado) - random.randint(1,10))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra spacing too.

@sourabhaa
Copy link
Contributor Author

Oops! I noticed the label after committing the suggested changes.

Copy link
Member

@JuiP JuiP left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thankyou!
Reviewed and tested; works just as expected. :)
Kindly check that any code that you contribute does not give any new flake8 warnings. I have pasted the ones I got here.

@@ -37,21 +37,50 @@ def __init__(self, level, fuente):
self.expresion = fuente.render(self.primero + simbolo[operador] + self.segundo + " = ? ",True,(255,0,0))
self.resultado = str(eval(self.primero+operacion[operador]+self.segundo))
self.vida = 0

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

juego.py:40:1: W293 blank line contains white space

juego.py Outdated

no_repeat_check_x = []
no_repeat_check_y = []
list_y = [int(sx(-90)), int(sx(-80)), int(sx(-60)), int(sx(-50)), int(sx(-40)), int(sx(-30)),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

juego.py:43:80: E501 line too long (101 > 79 characters)

juego.py Outdated
no_repeat_check_x = []
no_repeat_check_y = []
list_y = [int(sx(-90)), int(sx(-80)), int(sx(-60)), int(sx(-50)), int(sx(-40)), int(sx(-30)),
int(sx(-20)), int(sx(-10)), int(sx(-0))]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

juego.py:44:17: E128 continuation line under-indented for visual indent

juego.py Outdated
no_repeat_check_y = []
list_y = [int(sx(-90)), int(sx(-80)), int(sx(-60)), int(sx(-50)), int(sx(-40)), int(sx(-30)),
int(sx(-20)), int(sx(-10)), int(sx(-0))]
list_x = [int(sx(100)), int(sx(200)), int(sx(300)), int(sx(400)), int(sx(500)), int(sx(600)),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

juego.py:45:80: E501 line too long (101 > 79 characters)

juego.py Outdated
list_y = [int(sx(-90)), int(sx(-80)), int(sx(-60)), int(sx(-50)), int(sx(-40)), int(sx(-30)),
int(sx(-20)), int(sx(-10)), int(sx(-0))]
list_x = [int(sx(100)), int(sx(200)), int(sx(300)), int(sx(400)), int(sx(500)), int(sx(600)),
int(sx(700)), int(sx(800)),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

juego.py:46:17: E128 continuation line under-indented for visual indent
juego.py:46:44: W291 trailing whitespace

juego.py Outdated
if rand_coord_x not in no_repeat_check_x:
no_repeat_check_x.append(rand_coord_x)
return rand_coord_x
return int(sx(1000))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

juego.py:57:19: E271 multiple spaces after keyword

juego.py Outdated
rand_coord_y = random.choice(list_y)
if rand_coord_y not in no_repeat_check_y:
no_repeat_check_y.append(rand_coord_y)
return rand_coord_y
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

juego.py:66:40: W291 trailing whitespace

juego.py Outdated
no_repeat_check_y.append(rand_coord_y)
return rand_coord_y
return int(sx(-70))

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

juego.py:68:1: W293 blank line contains whitespace

juego.py Outdated
Comment on lines 70 to 74
ans_x_coord = rand_generator_x()
ans_y_coord = rand_generator_y()
self.preguntas.add(number(ans_x_coord,ans_y_coord, fuente.render(self.resultado,True,
(random.randint(0,255),random.randint(0,255),random.randint(0,255))),True))
for i in range(0,5):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

juego.py:72:80: E501 line too long (93 > 79 characters)
juego.py:72:88: E231 missing whitespace after ','
juego.py:73:33: E128 continuation line under-indented for visual indent
juego.py:73:50: E231 missing whitespace after ','
juego.py:73:55: E231 missing whitespace after ','
juego.py:73:72: E231 missing whitespace after ','
juego.py:73:77: E231 missing whitespace after ','
juego.py:73:80: E501 line too long (107 > 79 characters)
juego.py:73:94: E231 missing whitespace after ','
juego.py:73:101: E231 missing whitespace after ','
juego.py:74:25: E231 missing whitespace after ',' ```

juego.py Outdated
Comment on lines 82 to 83
self.preguntas.add(number(wrong_x_coord,wrong_y_coord,image_wrong,False))

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

juego.py:82:66: E231 missing whitespace after ','
juego.py:82:78: E231 missing whitespace after ','
juego.py:82:80: E501 line too long (85 > 79 characters)
juego.py:83:1: W293 blank line contains whitespace```

@quozl
Copy link

quozl commented Mar 28, 2021 via email

@chimosky
Copy link
Member

I had seen the changes were not flake8, but decided not to intervene. Perhaps we should not be automatic about it. Current head of master file juego.py has 328 lines, and 325 flake8 warnings. If we were to encourage changes that comply with flake8 instead of the existing style, we would have a file that has inconsistent style. A file with inconsistent style is possibly harder to read than a file with consistent style. One gets used to whatever style is visible. Yet we don't want to have to review flake8 changes to the whole file. For interest, autopep8 -a -p 80 -i juego.py brings it down to 55 warnings. Further manipulation of command line options may improve.

I agree, although she said this particular PR doesn't add new flake8 errors but I haven't checked for the existing errors and compared it to this one.

@JuiP
Copy link
Member

JuiP commented Mar 29, 2021

Agreed, the current master branch has a lot of flake8 errors.

@sourabhaa
Copy link
Contributor Author

I tried using autopep8 as suggested by @quozl. It reduced the warnings and errors. I looked into pep8 document to improve the rest manually but ended up with getting more errors. Can you suggest some resources that might help to improve?

@quozl
Copy link

quozl commented Mar 30, 2021 via email

@sourabhaa
Copy link
Contributor Author

I stored the flake8 errors before and after changes as @quozl suggested. I'm not able fix the flake8 errors completely. Since this issue is open in #16, I'll try figuring it out in future. Also, I'm working on issue #19 and wanted to open a PR for it. Is it okay to do it while this PR is open?

@chimosky
Copy link
Member

I stored the flake8 errors before and after changes as @quozl suggested. I'm not able fix the flake8 errors completely. Since this issue is open in #16, I'll try figuring it out in future. Also, I'm working on issue #19 and wanted to open a PR for it. Is it okay to do it while this PR is open?

I think you misunderstood what @quozl said, please remove the flake8-error.txt file as it's not needed.
You can definitely open a PR for something you're working on and when either gets merged first before the other, a rebase would solve the conflicts.

@sourabhaa
Copy link
Contributor Author

Thanks, I'll do it.

@sourabhaa
Copy link
Contributor Author

Not really. One method is to share the warning you are having problems resolving, or search for the warning in quotes. By far the best resource is the source code of flake8, but few people have the time to read it. My suggestion is for us to review and accept the changes without concern over flake8, given that the existing situation is so bad. Then flake8 fixes can happen in the next pull request. Otherwise you could be stuck for ages on flake8 fixes. Or, make sure you have not added warnings in your changes on this pull request. You can use git to rewind to before your work, save the flake8 output in a file, and compare with what you have now.

Sorry, I couldn't catch your words initially. I compared the warnings from previous code to my changes . There were 5 new warnings. I was able to fix those manually but I couldn't fix one warning.

 /Users/saurabhag/jamath-activity/juego.py:83:80: E501 line too long (81 > 79 characters)

@JuiP kindly review :)

@quozl
Copy link

quozl commented Apr 2, 2021 via email

@sourabhaa
Copy link
Contributor Author

I think I didn't convey the issue properly.

This error is from before the 21ac517 commit.

 /Users/saurabhag/jamath-activity/juego.py:83:80: E501 line too long (81 > 79 characters)

Now since I tried to fix E501 in line 83 by applying line break, I got this error.

/Users/saurabhag/jamath-activity/juego.py:80:34: E128 continuation line under-indented for visual indent
/Users/saurabhag/jamath-activity/juego.py:81:49: E127 continuation line over-indented for visual indent
/Users/saurabhag/jamath-activity/juego.py:84:50: E127 continuation line over-indented for visual indent

Also, there are roughly 50 E501 and F405 errors in the code prior to my changes . When I try to fix E501 by adding a line break, it leads to E127 or E128 errors. I do not know how else to fix them. One option is to add flake8 file which ignores these error codes(I'm not aware of the cons).

Here are those errors

/Users/saurabhag/jamath-activity/juego.py:5:1: F403 'from pygame.locals import *' used; unable to detect undefined names
/Users/saurabhag/jamath-activity/juego.py:19:21: F405 'Rect' may be undefined, or defined from star imports: pygame.locals
/Users/saurabhag/jamath-activity/juego.py:39:80: E501 line too long (89 > 79 characters)
/Users/saurabhag/jamath-activity/juego.py:80:34: E128 continuation line under-indented for visual indent
/Users/saurabhag/jamath-activity/juego.py:81:49: E127 continuation line over-indented for visual indent
/Users/saurabhag/jamath-activity/juego.py:84:50: E127 continuation line over-indented for visual indent
/Users/saurabhag/jamath-activity/juego.py:111:49: F405 'scale_x' may be undefined, or defined from star imports: pygame.locals
/Users/saurabhag/jamath-activity/juego.py:111:71: F405 'scale_y' may be undefined, or defined from star imports: pygame.locals
/Users/saurabhag/jamath-activity/juego.py:111:80: E501 line too long (80 > 79 characters)
/Users/saurabhag/jamath-activity/juego.py:127:26: F405 'scale_x' may be undefined, or defined from star imports: pygame.locals
/Users/saurabhag/jamath-activity/juego.py:130:26: F405 'scale_y' may be undefined, or defined from star imports: pygame.locals
/Users/saurabhag/jamath-activity/juego.py:151:34: F405 'QUIT' may be undefined, or defined from star imports: pygame.locals
/Users/saurabhag/jamath-activity/juego.py:154:36: F405 'MOUSEMOTION' may be undefined, or defined from star imports: pygame.locals
/Users/saurabhag/jamath-activity/juego.py:155:80: E501 line too long (98 > 79 characters)
/Users/saurabhag/jamath-activity/juego.py:156:80: E501 line too long (99 > 79 characters)
/Users/saurabhag/jamath-activity/juego.py:161:80: E501 line too long (100 > 79 characters)
/Users/saurabhag/jamath-activity/juego.py:162:80: E501 line too long (99 > 79 characters)
/Users/saurabhag/jamath-activity/juego.py:167:80: E501 line too long (99 > 79 characters)
/Users/saurabhag/jamath-activity/juego.py:168:80: E501 line too long (98 > 79 characters)
/Users/saurabhag/jamath-activity/juego.py:173:36: F405 'MOUSEBUTTONDOWN' may be undefined, or defined from star imports: pygame.locals
/Users/saurabhag/jamath-activity/juego.py:175:80: E501 line too long (102 > 79 characters)
/Users/saurabhag/jamath-activity/juego.py:176:80: E501 line too long (103 > 79 characters)
/Users/saurabhag/jamath-activity/juego.py:178:80: E501 line too long (104 > 79 characters)
/Users/saurabhag/jamath-activity/juego.py:179:80: E501 line too long (103 > 79 characters)
/Users/saurabhag/jamath-activity/juego.py:181:80: E501 line too long (103 > 79 characters)
/Users/saurabhag/jamath-activity/juego.py:182:80: E501 line too long (102 > 79 characters)
/Users/saurabhag/jamath-activity/juego.py:206:34: F405 'QUIT' may be undefined, or defined from star imports: pygame.locals
/Users/saurabhag/jamath-activity/juego.py:209:36: F405 'MOUSEMOTION' may be undefined, or defined from star imports: pygame.locals
/Users/saurabhag/jamath-activity/juego.py:210:80: E501 line too long (98 > 79 characters)
/Users/saurabhag/jamath-activity/juego.py:211:80: E501 line too long (99 > 79 characters)
/Users/saurabhag/jamath-activity/juego.py:216:80: E501 line too long (100 > 79 characters)
/Users/saurabhag/jamath-activity/juego.py:217:80: E501 line too long (99 > 79 characters)
/Users/saurabhag/jamath-activity/juego.py:222:80: E501 line too long (102 > 79 characters)
/Users/saurabhag/jamath-activity/juego.py:223:80: E501 line too long (101 > 79 characters)
/Users/saurabhag/jamath-activity/juego.py:235:36: F405 'MOUSEBUTTONDOWN' may be undefined, or defined from star imports: pygame.locals
/Users/saurabhag/jamath-activity/juego.py:237:80: E501 line too long (102 > 79 characters)
/Users/saurabhag/jamath-activity/juego.py:238:80: E501 line too long (103 > 79 characters)
/Users/saurabhag/jamath-activity/juego.py:241:80: E501 line too long (104 > 79 characters)
/Users/saurabhag/jamath-activity/juego.py:242:80: E501 line too long (103 > 79 characters)
/Users/saurabhag/jamath-activity/juego.py:245:80: E501 line too long (106 > 79 characters)
/Users/saurabhag/jamath-activity/juego.py:246:80: E501 line too long (105 > 79 characters)
/Users/saurabhag/jamath-activity/juego.py:249:36: F405 'KEYDOWN' may be undefined, or defined from star imports: pygame.locals
/Users/saurabhag/jamath-activity/juego.py:250:37: F405 'K_ESCAPE' may be undefined, or defined from star imports: pygame.locals
/Users/saurabhag/jamath-activity/juego.py:256:9: F841 local variable 'NUM_IMAGES' is assigned to but never used
/Users/saurabhag/jamath-activity/juego.py:292:80: E501 line too long (95 > 79 characters)
/Users/saurabhag/jamath-activity/juego.py:300:34: F405 'QUIT' may be undefined, or defined from star imports: pygame.locals
/Users/saurabhag/jamath-activity/juego.py:304:34: F405 'MOUSEBUTTONDOWN' may be undefined, or defined from star imports: pygame.locals
/Users/saurabhag/jamath-activity/juego.py:307:80: E501 line too long (110 > 79 characters)
/Users/saurabhag/jamath-activity/juego.py:308:80: E501 line too long (111 > 79 characters)
/Users/saurabhag/jamath-activity/juego.py:319:34: F405 'KEYDOWN' may be undefined, or defined from star imports: pygame.locals
/Users/saurabhag/jamath-activity/juego.py:320:37: F405 'K_ESCAPE' may be undefined, or defined from star imports: pygame.locals

@quozl
Copy link

quozl commented Apr 2, 2021

Okay, taking your 21ac517 the three introduced flake8 errors you refer to can be fixed with this change;

diff --git a/juego.py b/juego.py
index 08d716d..a8e4954 100644
--- a/juego.py
+++ b/juego.py
@@ -76,12 +76,13 @@ class expresion:
         self.preguntas = pygame.sprite.Group()
         ans_x_coord = rand_generator_x()
         ans_y_coord = rand_generator_y()
-        self.preguntas.add(number(ans_x_coord, ans_y_coord,
-                                 fuente.render(self.resultado, True,
-                                                (random.randint(0, 255),
-                                                 random.randint(0, 255),
-                                                 random.randint(0, 255))),
-                                                 True))
+        self.preguntas.add(
+            number(ans_x_coord, ans_y_coord,
+                   fuente.render(
+                       self.resultado, True, (random.randint(0, 255),
+                                              random.randint(0, 255),
+                                              random.randint(0, 255))),
+                   True))
         for i in range(0, 5):
             if random.randint(0, 1) == 0:
                 wrong = str(int(self.resultado) - random.randint(1, 10))

This vertically aligns the True with the argument list in which it appears; easing comprehension for a new reader.

A few lines down from here, you can see where a previous author has created local variables such as image_wrong to avoid similar indentation or style problems. It too could take the same change, thus;

diff --git a/juego.py b/juego.py
index 08d716d..1564de0 100644
--- a/juego.py
+++ b/juego.py
@@ -76,30 +76,25 @@ class expresion:
         self.preguntas = pygame.sprite.Group()
         ans_x_coord = rand_generator_x()
         ans_y_coord = rand_generator_y()
-        self.preguntas.add(number(ans_x_coord, ans_y_coord,
-                                 fuente.render(self.resultado, True,
-                                                (random.randint(0, 255),
-                                                 random.randint(0, 255),
-                                                 random.randint(0, 255))),
-                                                 True))
+        self.preguntas.add(
+            number(ans_x_coord, ans_y_coord,
+                   fuente.render(
+                       self.resultado, True, (random.randint(0, 255),
+                                              random.randint(0, 255),
+                                              random.randint(0, 255))),
+                   True))
         for i in range(0, 5):
             if random.randint(0, 1) == 0:
                 wrong = str(int(self.resultado) - random.randint(1, 10))
             else:
                 wrong = str(int(self.resultado) + random.randint(1, 10))
-            wrong_x_coord = rand_generator_x()
-            wrong_y_coord = rand_generator_y()
-            image_wrong = fuente.render(
-                wrong, True, (random.randint(
-                    0, 255), random.randint(
-                    0, 255), random.randint(
-                    0, 255)))
             self.preguntas.add(
-                number(
-                    wrong_x_coord,
-                    wrong_y_coord,
-                    image_wrong,
-                    False))
+                number(rand_generator_x(), rand_generator_y(),
+                       fuente.render(
+                           wrong, True, (random.randint(0, 255),
+                                         random.randint(0, 255),
+                                         random.randint(0, 255))),
+                       False))
 
 
 def cargar_imagen(nombre, trasnparent=False):

I hope that shows how E127 and E128 after E501 can be remediated.

@sourabhaa
Copy link
Contributor Author

Thanks, I was able to fix all E501 errors. Should I create a file to ignore F405 warnings?

@quozl quozl merged commit 7c5acd5 into sugarlabs:master Apr 4, 2021
@quozl
Copy link

quozl commented Apr 4, 2021

No, the F403 and F405 should be fixed. Also the F841. Once these are fixed, flake8 will be able to check much more, and we'll need a .flake8 to suppress E402, see the Chat Activity for example file and explanation.

@sourabhaa
Copy link
Contributor Author

okay, I'll fix it in next PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Overlapping digits
4 participants