Is there anyone here who hasn't successfully survived monday?
It is interesting, though I've tried something similar on a javascript AI and immediately realized a whole lot of implementation problems.
It works well as a piece limited, but in the greater whole, the AI chooses implementation versions that do not really work.
For instance, I had it generate a 3x3 gameboard with card objects created based on a prototype object that is supposed to have 4 random values from 1-9 and functions to access its neighbors dynamically based on the current position.
While this isn't wrong, that's not really dynamic. It works if you make sure that you tell the card it's new position every time you change on what tile it is,
but it cannot dynamically detect the neighbors.
A dynamic solution would be to use a function to access the gameboard, find the current row & column indexes and then use those to calculate the neighbors. This also only works on a fixed gameboard size with fixed dimensions, since the gameboard is automatically divided into rows and columns.
This also fixes how the gameboard's tiles are accessible, because it predefines the size of the gameboard during creation.
Instead, a different and more flexible solution would've been to have the gameboard creates as containing an array of x tiles, giving the gameboard a width & height and rather than using direct +/- operations on fixed tiles, using modulo to dynamically access the correct neighbors even if the size & width change.
So it's a correct solution that might not work in the actual project, due to restrictions in what choices it has made for the implementation.
I think it's a nifty thing for simple and straightforward operations, but I don't think it can, in the solution, correctly account of implentation-based restrictions in how it's going to have to interact in the greater whole. The particular choice made by the AI does provide the fastest solution (predefined values, even less math) but it's not necessarily giving the solution that would actually work with the project.
I wonder if anyone managed to get it to work with something like PixiJS and create a simple visual game - because I wonder if the AI would detect the necessary restrictions in rendering hierarchy.
I think some of the things to consider here, is that AI should be used to help, rather than to build completely (at this stage at least) and, like you say - it's not wrong necessarily, but just not ideal. In my experience, AI won't ever give you ideal since that's where some of our humanity and problem solving comes in. Also, remember it's an iterative process, so give it your feedback to improve it. Just like you would if you hired an outside developer/artist that doesn't do what you want.
That said, can I ask what AI you were using to Generate? Because that changes the output MASSIVELY. Let me share with you what I've just done in GPT based on your code. For reference, both of the below are ChatGPT 4o and both are brand new unique conversatons.
Can you improve this Javascript based on the users request?
For instance, I had it generate a 3x3 gameboard with card objects created based on a prototype object that is supposed to have 4 random values from 1-9 and functions to access its neighbors dynamically based on the current position. //
Dynamic values Array: The values array is now dynamically generated for each card during initialization.
Boundary Handling: The neighbor functions (top, bottom, left, right) now check boundaries to avoid accessing undefined array elements.
Initialization Method: Added an init method to the prototype for setting up row, col, and values properties.
Object Creation: Used Object.create and card.init to ensure each card gets unique values.
This code should now correctly create a 3x3 gameboard with cards having unique values and correctly handle neighbor lookups.
A User is discussing trouble using AI Language Models to write code for a Java project. As I am unfamiliar with Java, can you take a look at his query below and perhaps improve his code to something more appropriate? It is interesting, though I've tried something similar on a javascript AI and immediately realized a whole lot of implementation problems. It works well as a piece limited, but in the greater whole, the AI chooses implementation versions that do not really work. For instance, I had it generate a 3x3 gameboard with card objects created based on a prototype object that is supposed to have 4 random values from 1-9 and functions to access its neighbors dynamically based on the current position. This is the result // Prototype object for the card const cardPrototype = { values: Array.from({ length: 4 }, () => Math.floor(Math.random() * 9) + 1), top: function() { return gameboard[this.row - 1][this.col]; }, bottom: function() { return gameboard[this.row + 1][this.col]; }, left: function() { return gameboard[this.row][this.col - 1]; }, right: function() { return gameboard[this.row][this.col + 1]; } }; // Create a 3x3 gameboard with card objects const gameboard = Array.from({ length: 3 }, () => Array.from({ length: 3 }, () => Object.create(cardPrototype)) ); // Assign row and column properties to each card gameboard.forEach((row, i) => { row.forEach((card, j) => { card.row = i; card.col = j; }); }); While this isn't wrong, that's not really dynamic. It works if you make sure that you tell the card it's new position every time you change on what tile it is, but it cannot dynamically detect the neighbors. A dynamic solution would be to use a function to access the gameboard, find the current row & column indexes and then use those to calculate the neighbors. This also only works on a fixed gameboard size with fixed dimensions, since the gameboard is automatically divided into rows and columns. This also fixes how the gameboard's tiles are accessible, because it predefines the size of the gameboard during creation. Instead, a different and more flexible solution would've been to have the gameboard creates as containing an array of x tiles, giving the gameboard a width & height and rather than using direct +/- operations on fixed tiles, using modulo to dynamically access the correct neighbors even if the size & width change. So it's a correct solution that might not work in the actual project, due to restrictions in what choices it has made for the implementation. I think it's a nifty thing for simple and straightforward operations, but I don't think it can, in the solution, correctly account of implentation-based restrictions in how it's going to have to interact in the greater whole. The particular choice made by the AI does provide the fastest solution (predefined values, even less math) but it's not necessarily giving the solution that would actually work with the project. I wonder if anyone managed to get it to work with something like PixiJS and create a simple visual game - because I wonder if the AI would detect the necessary restrictions in rendering hierarchy.
It seems the user is trying to dynamically handle the position of cards on a gameboard in a JavaScript context, and they would like a more flexible solution that doesn't rely on fixed positions. Here's an improved version of the code that dynamically calculates the neighbours and can adapt to changes in the gameboard's size:
JavaScript:
// Card constructor function
function Card(row, col, gameboard) {
this.row = row;
this.col = col;
this.gameboard = gameboard;
this.values = Array.from({ length: 4 }, () => Math.floor(Math.random() * 9) + 1);
}
Card.prototype.getNeighbour = function (dRow, dCol) {
const newRow = this.row + dRow;
const newCol = this.col + dCol;
if (newRow >= 0 && newRow < this.gameboard.length && newCol >= 0 && newCol < this.gameboard[0].length) {
return this.gameboard[newRow][newCol];
}
return null;
};
Card.prototype.top = function () {
return this.getNeighbour(-1, 0);
};
Card.prototype.bottom = function () {
return this.getNeighbour(1, 0);
};
Card.prototype.left = function () {
return this.getNeighbour(0, -1);
};
Card.prototype.right = function () {
return this.getNeighbour(0, 1);
};
// Function to create a gameboard
function createGameboard(rows, cols) {
const gameboard = Array.from({ length: rows }, (_, row) =>
Array.from({ length: cols }, (_, col) => new Card(row, col, gameboard))
);
// Assign the gameboard reference after creation
gameboard.forEach(row => row.forEach(card => card.gameboard = gameboard));
return gameboard;
}
// Create a 3x3 gameboard
const gameboard = createGameboard(3, 3);
// Example: Access neighbours of the card at (1, 1)
const card = gameboard[1][1];
console.log('Top:', card.top());
console.log('Bottom:', card.bottom());
console.log('Left:', card.left());
console.log('Right:', card.right());
Explanation:
Card Constructor: The Card function is used to create card objects with dynamic row and column properties. Each card also holds a reference to the gameboard it belongs to.
getNeighbour Method: This method calculates the new row and column indices based on the current position and checks if the new indices are within bounds. If they are, it returns the neighbouring card; otherwise, it returns null.
Direction Methods: The top, bottom, left, and right methods use getNeighbour to find the card in the corresponding direction.
createGameboard Function: This function creates a gameboard of the specified size and populates it with cards. Each card is initially created without a reference to the gameboard, but after the gameboard is fully created, each card's gameboard reference is updated.
This approach allows the gameboard to dynamically calculate neighbours regardless of the board size and ensures that the card objects are aware of their own positions and the gameboard they belong to. This should address the user's concerns about flexibility and dynamic interaction in the project.
So, I'm not sure how much credit you give those responses? I'm not trying to "prove you wrong" or anything like that, just trying to say "have you tried this?" - you might look at this code and still call it bullshit, since I don't really know what I'm talking about when it comes to Java! I just thought it'd be interesting to get your perspective on it.
Sounds like you're having an existential crisis, my friend.
Indeed, what is the point of this meagre existence we've been given? This short lifespan which represents such an impossibly small fractal of the universes existence.
Sounds like you're having an existential crisis, my friend.
Indeed, what is the point of this meagre existence we've been given? This short lifespan which represents such an impossibly small fractal of the universes existence.