我发现这个有效的解决方案
private int[] winningPatterns = { 0b111000000, 0b000111000, 0b000000111, // rows
0b100100100, 0b010010010, 0b001001001, // cols
0b100010001, 0b001010100 // diagonals
};
/** Returns true if thePlayer wins */
private boolean hasWon(int thePlayer) {
int pattern = 0b000000000; // 9-bit pattern for the 9 cells
for (int row = 0; row < 3; ++row) {
for (int col = 0; col < 3; ++col) {
if (cells[row][col].content == thePlayer) {
pattern |= (1 << (row * 3 + col));
}
} …
Run Code Online (Sandbox Code Playgroud) 我正在考虑从Dart转到ES6,但Chrome似乎不支持对我来说至关重要的新导入语句.
我使用了这个站点的(命名导出)代码:http://www.2ality.com/2014/09/es6-modules-final.html
我甚至试过了
<module import="main"><module>
Run Code Online (Sandbox Code Playgroud)
我收到错误:"意外的令牌导入"
如果他们在最终版本发布之前支持它的任何信息?
码:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>ES6</title>
</head>
<body bgcolor="blue">
<script type="module" src="main.js"></script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
main.js
import { square, diag } from 'lib';
console.log(square(11)); // 121
console.log(diag(4, 3)); // 5
Run Code Online (Sandbox Code Playgroud)
lib.js:
export const sqrt = Math.sqrt;
export function square(x) {
return x * x;
}
export function diag(x, y) {
return sqrt(square(x) + square(y));
}
Run Code Online (Sandbox Code Playgroud) 我将JavaScript背景图像加载器转换为Dart,有点像:Javascript图像加载器
我使用Timer来检查图像是否全部加载.这很好用.
但是在Dart中有可连接的Futures,我想知道你是否可以链接ImageElements的后台加载......
ImageElement a = new ImageElement();
ImageElement b = new ImageElement();
ImageElement c = new ImageElement();
Future.wait([a.src='a.jpg', b.src='b.jpg', c.src='ca.jpg'])
.then((List responses) => chooseBestResponse(responses))
.catchError((e) => handleError(e));
Run Code Online (Sandbox Code Playgroud)
当然分配src和实际的图像加载是异步的,所以这不起作用......
加载后,我还需要为每个图像执行一些代码.
也许我需要编写自己的FutureImageElement类,但我想我先问...
有任何想法吗 ?
我正在尝试用注释掉的一行编写一些Python示例代码:
user_by_email = session.query(User)\
.filter(Address.email=='one')\
#.options(joinedload(User.addresses))\
.first()
Run Code Online (Sandbox Code Playgroud)
我也尝试过:
user_by_email = session.query(User)\
.filter(Address.email=='one')\
# .options(joinedload(User.addresses))\
.first()
Run Code Online (Sandbox Code Playgroud)
但我得到IndentationError:意外的缩进.如果我删除注释掉的行,代码就可以了.我很确定我只使用空格(Notepad ++ screenshot):
我正在尝试接收有关比特币区块链中新块的通知.我正在使用此代码,但是从2010年左右开始打印数百个块.
import org.bitcoinj.core.*;
import org.bitcoinj.net.discovery.DnsDiscovery;
import org.bitcoinj.params.MainNetParams;
import org.bitcoinj.store.BlockStore;
import org.bitcoinj.store.MemoryBlockStore;
public class BlockChainMonitorTest {
BlockChainMonitorTest() throws Exception {
NetworkParameters params = MainNetParams.get();
BlockStore bs = new MemoryBlockStore(params);
BlockChain bc = new BlockChain(params, bs);
PeerGroup peerGroup = new PeerGroup(params, bc);
peerGroup.setUserAgent("PeerMonitor", "1.0");
peerGroup.setMaxConnections(4);
peerGroup.addPeerDiscovery(new DnsDiscovery(params));
bc.addNewBestBlockListener((StoredBlock block) -> {
System.out.println("addNewBestBlockListener");
System.out.println(block);
});
//peerGroup.setFastCatchupTimeSecs(1483228800); // 2017-01-01
peerGroup.start();
peerGroup.waitForPeers(4).get();
Thread.sleep(1000 * 60 * 30);
peerGroup.stop();
}
public static void main(String[] args) throws Exception {
new BlockChainMonitorTest();
}
}
Run Code Online (Sandbox Code Playgroud)
我想只听新块.有任何想法吗 ? …
我需要在java中编写FLAC文件.之前我将音频输入写入WAV文件,然后使用外部转换器将其转换为FLAC文件
我正在研究JFlac以找到可以通过其编写FLAC文件的任何API.我发现java中的AudioFileFormat.TYPE仅支持以下文件格式 - AIFC,AIFF,SND,AU,WAVE.
我想有一种方法可以从麦克风中捕获音频,并使用Audiosystem.write等API将其写入FLAC文件而不是WAV文件.
请建议可以解决我的问题的方法或API.
这是我用来测试的代码:
#include <iostream>
#include <boost/interprocess/managed_mapped_file.hpp>
#include <boost/container/map.hpp>
#include <boost/interprocess/managed_external_buffer.hpp>
#include <boost/interprocess/allocators/node_allocator.hpp>
#include <boost/container/vector.hpp>
namespace bi = boost::interprocess;
int main() {
bi::managed_mapped_file mmfile(bi::open_or_create, "map_iv.dat", 10000000);
typedef bi::allocator<int, bi::managed_mapped_file::segment_manager> int_allocator;
typedef boost::container::vector<int, int_allocator> MyVec;
typedef std::pair<const std::string, MyVec> MyPair;
typedef std::less<std::string> MyLess;
typedef bi::node_allocator<MyPair, bi::managed_mapped_file::segment_manager> node_allocator_t;
typedef boost::container::map<std::string, MyVec, std::less<std::string>, node_allocator_t> MyMap;
MyMap * mapptr = mmfile.find_or_construct<MyMap>("mymap")(mmfile.get_segment_manager());
(*mapptr)["Hello"].push_back(17);
long long s = mapptr->size();
std::cout << s << ' ';
std::cout << (*mapptr)["World"][0] << ' ';
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我在Visual Studio 2017中收到此错误消息:
boost_1_69_0\boost\container\vector.hpp(294): …
Run Code Online (Sandbox Code Playgroud) 有谁知道为什么glmatrix(1.x)定义mat4.translate像这样:
/**
* Translates a matrix by the given vector
*
* @param {mat4} mat mat4 to translate
* @param {vec3} vec vec3 specifying the translation
* @param {mat4} [dest] mat4 receiving operation result. If not specified result is written to mat
*
* @returns {mat4} dest if specified, mat otherwise
*/
mat4.translate = function (mat, vec, dest) {
var x = vec[0], y = vec[1], z = vec[2],
a00, a01, a02, a03,
a10, a11, a12, a13,
a20, a21, a22, …
Run Code Online (Sandbox Code Playgroud) 我在数据科学和 pytorch 方面没有那么丰富的经验,并且我在实现至少任何东西方面都遇到了问题(目前我正在为分割任务制作一个神经网络)。存在某种内存问题,尽管它没有任何意义 - 每个纪元占用的内存都比上升时要少得多
import torch
from torch import nn
from torch.autograd import Variable
from torch.nn import Linear, ReLU6, CrossEntropyLoss, Sequential, Conv2d, MaxPool2d, Module, Softmax, Softplus ,BatchNorm2d, Dropout, ConvTranspose2d
import torch.nn.functional as F
from torch.nn import LeakyReLU,Tanh
from torch.optim import Adam, SGD
import numpy as np
import cv2 as cv
def train(epoch,model,criterion, x_train, y_train, loss_val):
model.train()
tr_loss = 0
# getting the training set
x_train, y_train = Variable(x_train), Variable(y_train)
# converting the data into GPU format
# clearing the …
Run Code Online (Sandbox Code Playgroud) 因此,我尝试从 Three.js 示例中克隆士兵模型,因为稍后我想要多个模型: https: //thirdjs.org/examples/webgl_animation_skinning_blending.html
我将第 93 行更改为:
const loader = new GLTFLoader();
loader.load( 'https://threejs.org/examples/models/gltf/Soldier.glb', function ( gltf ) {
model = gltf.scene.clone();
scene.add( model );
model.traverse( function ( object ) {
if ( object.isMesh ) object.castShadow = true;
} );
Run Code Online (Sandbox Code Playgroud)
但现在士兵已经很大了。
为什么会发生这种情况?有解决办法吗?
这是一个显示问题的 jsfiddle:
https://jsfiddle.net/paranoidray/jLpzk374/22/
如果您查看 jsfiddle 并更改第 93 行并删除 clone() 调用。一切又恢复正常了...
任何帮助将非常感激。
所以我使用 boost::beast 作为 WebSocket 服务器。我想接收二进制消息并使用 nlohmann::json 解析它。但是我收到一条错误消息:
3 个重载都不能转换参数“nlohmann::detail::input_adapter”
这是一些代码:
boost::beast::flat_buffer buffer;
ws.read(buffer);
if (!ws.got_text()) {
ws.text(false);
json request = json::from_msgpack(msgpack);
ws.write( json::to_msgpack(request) ); // echo request back
}
Run Code Online (Sandbox Code Playgroud)
如果我尝试静态转换为 std::vector 我得到: E0312 / 没有合适的用户定义转换
boost::beast::flat_buffer buffer;
ws.read(buffer);
if (!ws.got_text()) {
ws.text(false);
boost::asio::mutable_buffer req = buffer.data();
//unsigned char* req2 = static_cast<unsigned char*>(req); // does not work
//std::vector<std::uint8_t> req2 = static_cast<std::vector<std::uint8_t>>(req); // does not work
json request = json::from_msgpack(buffer.data());
ws.write(boost::asio::buffer(json::to_msgpack(request)));
}
Run Code Online (Sandbox Code Playgroud)
如何从缓冲区中获取二进制数据以便 nkohman::json 可以解析它?
boost ×2
c++ ×2
java ×2
python ×2
allocator ×1
audio ×1
bitcoinj ×1
boost-asio ×1
dart ×1
ecmascript-6 ×1
indentation ×1
jgrapht ×1
matrix ×1
msgpack ×1
python-2.7 ×1
pytorch ×1
three.js ×1
tic-tac-toe ×1
wav ×1
webgl ×1