-
Notifications
You must be signed in to change notification settings - Fork 47
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
Add BishopsGraph
, RooksGraph
, and QueensGraph
#454
Conversation
BishopsGraph
, RooksGraph
, and QueensGraph
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice pull request with some really useful examples. There is very little redundant work thanks to clever use of other line piece graphs, along with graph products, to give the more complicated graphs. Some thought is necessary to decide what's best semantics-wise for the bishop's graph, given that in its current form, output is very convenient but doesn't quite line up with the quoted definition from Wolfram MathWorld. Whether you decide to change the output format, or instead just change the definition you give in the documentation to make it consistent with the implementation, this will be a great feature.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I started to make many small documentation-related changes, but then I realised that it would be quicker and easier for me to just make the changes and push then to your branch. So I'm going to do just that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for adding these. I haven't looked at the methods closely, but there is one problem that I found (commented on below).
I also think it would be nice (although I don't insist on it) if the vertices were labelled with the co-ordinates of their square. Ideally "A1" etc - but we can't do that since there are only 26 letters but we want to make arbitrarily large graphs 🙂 If it would be easy to add, then, could you please add vertex labels like we have for KingsGraph
:
gap> DigraphVertexLabels(KingsGraph(4, 7));
[ [ 1, 1 ], [ 2, 1 ], [ 3, 1 ], [ 4, 1 ], [ 1, 2 ], [ 2, 2 ], [ 3, 2 ],
[ 4, 2 ], [ 1, 3 ], [ 2, 3 ], [ 3, 3 ], [ 4, 3 ], [ 1, 4 ], [ 2, 4 ],
[ 3, 4 ], [ 4, 4 ], [ 1, 5 ], [ 2, 5 ], [ 3, 5 ], [ 4, 5 ], [ 1, 6 ],
[ 2, 6 ], [ 3, 6 ], [ 4, 6 ], [ 1, 7 ], [ 2, 7 ], [ 3, 7 ], [ 4, 7 ] ]
so that the vertex with label [1,1]
would correspond to the square A1
, and [2,4]
to B4
, etc.
Hi, thanks for reviewing this pull request @wilfwilson! I just wanted to quickly respond to this comment you sent a few days ago:
Basically, I was a bit surprised at first that the king's graph had vertex labels, since I do not remember programming these into that function and I could not find any later edits that added them! After looking at it for a little bit I think the vertex labeling is coming from the use of the Cartesian product function, since the queen's and rook's graphs also have it while the bishop's graph does not (the bishop's graph function is also the only one that does not rely on the Cartesian product of two graphs). So I've decided for consistency's sake I will try and add the vertex labeling to the bishop's graph as well (and probably also to the knight's graph in a separate pull request). |
Thanks for the reply @finnbuck, I'm sorry I broke your tests but I think I've just fixed them now (I hope). The 'problem' was that I switched the meaning of the arguments The reason I made the change is that I wanted the The reason that |
So please feel free to give it a go, labelling the vertices of the digraphs. I'm happy to sort it out if it proves too tricky. If we're going to do it, I really think it should be done consistently with the existing named pieces, so that the
(in particular note it has the label Once the vertex labels are done I'll be happy for this to be merged! Thanks again. |
Apologies for the wait! I think I've just about figured out how to do the vertex labels by now and will hopefully be pushing those changes later this evening... |
I'm taking a look at this again, thanks @finnbuck |
6b7e124
to
f953336
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your patience @finnbuck.
I've updated the pull request so that all five of the of the chess piece graph functions are 'consistent', in the way that they use labels that they use for vertices.
i.e. vertex 1 is always [1, 1]
, vertex 2
is [2, 1]
, vertex 3
is [3, 1]
, ..., vertex m
is [m, 1]
, vertex m+1
is [1, 2]
, and so on.
This way, the QueensGraph(m, n)
contains KingsGraph(m, n)
, RooksGraph(m, n)
, and BishopsGraph(m, n)
as subdigraphs, and the vertex labels are the same in all cases.
I also reworked the documentation a bit.
Let's see if the tests pass!
Thank you @wilfwilson! Looks like all the checks have indeed passed. I've had a read through the changes and it all looks quite sensible to me. I'll try to keep in mind some of these tricks to make my code more readable and maintainable in the future! |
This pull request adds constructor functions for the Bishop's, Rook's and Queen's graphs.